I'm trying to create a data table variable that is a string representation of date in the format yyyy-mm-dd. I can define a variable in the proper format and set it as a data table variable as shown here.
datetime = "2021-08-01";
dt = Current Data Table();
dt << Set Table Variable( "LastRunDate", datetime );
However, I want to obtain the current datetime and convert it to a string in the format yyyy-mm-dd so that I can save it as a data table variable. What is the best/easiest way to accomplish this? I
If you want to convert it into a string with padding for zeros this should work in all cases:
Char(Year(Today())) || "-" || Substr("00", 1, 2 - Length(Char(Month(Today())))) || Char(Month(Today())) || "-" || Substr("00", 1 , 2 - Length(Char(Day(Today())))) || Char(Day(Today()));Or then you can use something like this which should also work in most of the cases (not sure if JMP will have issue with this specific format on some regional settings):
Format(Today(), "yyyy-mm-dd");Names Default To Here(1);
dt = New Table("Untitled 3",
Add Rows(0),
Compress File When Saved(1),
New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([]))
);
dt << Set Table Variable("LastRunDate", Format(Today(), "yyyy-mm-dd"));
If you want to convert it into a string with padding for zeros this should work in all cases:
Char(Year(Today())) || "-" || Substr("00", 1, 2 - Length(Char(Month(Today())))) || Char(Month(Today())) || "-" || Substr("00", 1 , 2 - Length(Char(Day(Today())))) || Char(Day(Today()));Or then you can use something like this which should also work in most of the cases (not sure if JMP will have issue with this specific format on some regional settings):
Format(Today(), "yyyy-mm-dd");Names Default To Here(1);
dt = New Table("Untitled 3",
Add Rows(0),
Compress File When Saved(1),
New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([]))
);
dt << Set Table Variable("LastRunDate", Format(Today(), "yyyy-mm-dd"));
Both solutions worked. Thanks for the quick suggestion.