Informat (ParseDate) function with timeHi,
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?
ScriptingWindowsRe: Informat (ParseDate) function with timeCheck 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);
Re: Informat (ParseDate) function with timeHere 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";