cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Choose Language Hide Translation Bar
jueefo
Level II

Informat (ParseDate) function with time

Hi,

 

I have a question about Informat function (or its alias ParseDate). If I have a string with date and time information, and I try to parse date on JMP 15.2.0.

 

str="2022-10-22 16:25:37";

datetime= Informat( str, "yyyy-mm-dd HH:mm:ss" );
show(type(datetime));
show(datetime);

I get output different kind of outputs, depending on date time settings (Win 10).

 

Regional format English (United Kingdom):
str = "2022-10-22 16:23:37";
Type(datetime) = "Date";
datetime = 22Oct2022:16:23:37;

 

Or Regional format Finnish (Finland):

str = "2022-10-22 16:23:37";
Type(datetime) = "Number";
datetime = .;

Is there a function that could parse time also? Or are there suggestions how this could be done?

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Informat (ParseDate) function with time

Here is one way to handle the issue

str="2022-10-22 16:25:37";

datetime = datemdy(num(word(2,str," -:")),
	num(word(3,str," -:")),
	num(word(1,str," -:")) ) +
	3600*num(word(4,str," -:")) +
	60 * num(word(5,str," -:")) +
	num(word(6,str," -:")
);
show(format(datetime,"m/d/y h:m:s"));

It shows in the log

Format(datetime, "m/d/y h:m:s") = "10/22/2022 4:25:37 PM";
Jim

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Informat (ParseDate) function with time

Check out if using << Use Locale() helps at all.

JMP was fairly bad at managing managing time (and dates) before JMP16. I would most likely parse the string to year, month, day, hour, minute and second. Then sum those to get date_time. With JMP16 you could most likely just use Format Pattern

 

Maybe this can give some ideas:

 

Names Default To Here(1);

str = "2022-10-22 16:25:37";

date = Word(1, str, " ");
time = Word(2, str, " ");
y = Num(Word(1, date, "-"));
m = Num(Word(2, date, "-"));
d = Num(Word(3, date, "-"));

time_separator = Left(Regex(Format(Today(), "h:m:s"), "\d", "", GLOBALREPLACE), 1);

hh = Num(Word(1, time, time_separator));
mm = Num(Word(2, time, time_separator));
ss = Num(Word(3, time, time_separator));

date_time = Date DMY(d, m, y) + hh * 60 * 60 + mm * 60 + ss;
AsDate(date_time);

 

 

-Jarmo
jueefo
Level II

Re: Informat (ParseDate) function with time

I have used << Use Locale() to overcome issues with date and time formats. The example you provided did not solve issue, I  think that I come back to this later when I have time (pun intended). The issue with the example is most probably solved with << Use Locale(). I'll also try Format Pattern, if I get newer version of the JMP.

 

Thanks again sharing your knowledge.

txnelson
Super User

Re: Informat (ParseDate) function with time

Here is one way to handle the issue

str="2022-10-22 16:25:37";

datetime = datemdy(num(word(2,str," -:")),
	num(word(3,str," -:")),
	num(word(1,str," -:")) ) +
	3600*num(word(4,str," -:")) +
	60 * num(word(5,str," -:")) +
	num(word(6,str," -:")
);
show(format(datetime,"m/d/y h:m:s"));

It shows in the log

Format(datetime, "m/d/y h:m:s") = "10/22/2022 4:25:37 PM";
Jim
jueefo
Level II

Re: Informat (ParseDate) function with time

Thank you, this example works for the datetime settings tested.

hogi
Level XII

Re: Informat (ParseDate) function with time

It seems that in Jmp 15.2 Informat just ignored fancy patterns like 

datetime= Informat( str, "yyyy-mm-dd HH:mm:ss" );

Even pattern = "hello" results in 

hogi_0-1710792939811.png

 

In later versions, Jmp will tell the user:

Unknown format: hello

 

 

What works:
Informat with the option Format Pattern

str="2022-10-22 16:25:37";
datetime= Informat( str, "Format Pattern", "<YYYY></><MM></><DD> <hh><:><mm><:><ss>" );
show(type(datetime));
show(datetime);