cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
TONG_SUPER
Level I

MM/DD HH:MM conversion how to do

I have a time Colum in a odd format  ( do not even have Year in and  need help converting to a simply   YY/MM/DD HH:MM

Thanks

 

tong

 

Time
[08/06-19:07:34.981]
[08/06-19:08:05.927]
[08/06-19:08:14.270]
[08/06-19:08:26.331]
7 REPLIES 7
txnelson
Super User

Re: MM/DD HH:MM conversion how to do

Here is the formula I used to do the conversion

Date MDY( Num( Word( 1, :Time, "[/" ) ), Num( Word( 2, :Time, "[/-" ) ), 2024 )
+Informat( Word( 3, :Time, "[/-]" ), "hh:mm:ss" )

txnelson_0-1724716233316.png

 

Jim
TONG_SUPER
Level I

Re: MM/DD HH:MM conversion how to do

Thank you so much

TONG_SUPER
Level I

Re: MM/DD HH:MM conversion how to do

I had another question.  I can do MM/DD/YYYY but i do not know how to add the time string in to add in it 

Source Table
20240207_163752
20240208_132212
20240320_180945
20240321_062705

TONG_SUPER_0-1724868518757.png

DMY conver=Date DMY(Num( Munger( :Source Table, 7, 2 ) ),Num( Munger( :Source Table, 5, 2 ) ),Num( Left( :Source Table, 4 ) ))

txnelson
Super User

Re: MM/DD HH:MM conversion how to do

JMP Date/Time values are stored as the number of seconds since Midnight, January 1, 1904.  So once you have input the Date part using the DateDMY, the time part just needs to be added to the date part. The time part simply becomes the number of hours*3600 + number of minutes*60 + number of seconds.  I don't know how to interpret the 163752, but all you need to do is to determine the number of seconds in the day it represents and then add it to the Date part, and you will have your answer.

Jim
TONG_SUPER
Level I

Re: MM/DD HH:MM conversion how to do

sorry i was not clear.  163752  is kind of military time for  HHMMSS  eg 4 pm 37 min and 52 sec

txnelson
Super User

Re: MM/DD HH:MM conversion how to do

Given the method I specified above, the formula is

DMY conver = Date DMY(
	Num( Munger( :Source Table, 7, 2 ) ),
	Num( Munger( :Source Table, 5, 2 ) ),
	Num( Left( :Source Table, 4 ) )
) + Num( Munger( :Source Table, 10, 2 ) ) * 3600
+Num( Munger( :Source Table, 12, 2 ) ) * 60
+Num( Munger( :Source Table, 14, 2 ) )

txnelson_0-1724875205108.png

 

Jim
jthi
Super User

Re: MM/DD HH:MM conversion how to do

There are a lot of different methods of converting strings to datetimes in JMP. Building it from ground up by splitting it from parts is the method which has the highest success rate but there can be easier methods, such as Format Pattern (note that In Format() has << Use Locale argument which you might need sometimes)

Names Default To Here(1);

strs = {"20240207_163752", "20240208_132212", "20240320_180945", "20240321_062705"};

For Each({str}, strs,
	datetime = Informat(str, "Format Pattern", "<YYYY><MM><DD>_<hh24><mm><ss>");
	Write("\!N", str, " converted to time is ", datetime);
);

20240207_163752 converted to time is 07Feb2024:16:37:52
20240208_132212 converted to time is 08Feb2024:13:22:12
20240320_180945 converted to time is 20Mar2024:18:09:45
20240321_062705 converted to time is 21Mar2024:06:27:05

If using as formula replace str with your column

jthi_0-1724910931361.png

 

https://www.jmp.com/support/help/en/18.0/#page/jmp/datetime-functions-and-formats.shtml# - Scripting Guide

https://www.jmp.com/support/help/en/18.0/#page/jmp/date-and-time-functions.shtml#ww2531887 - JSL Syntax Reference

-Jarmo