question

Kyle Y avatar image
1 Like"
Kyle Y asked Steven Hamoen answered

how to use DateTime class

2019-09-05 01:23:14
I got a string like before, I am wondering how to convert to DateTime format and then retrieve Year(2019) and minute(23) directly? Is it possible? Thank you .
FlexSim 19.0.0
datetime
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jacob Gillespie avatar image Jacob Gillespie ♦ commented ·

The ability to parse DateTime strings with the DateTime class will be available in FlexSim 20.0

1 Like 1 ·
CSN avatar image CSN commented ·

Please send the string you want before conversion and the format you want to convert after conversion. Let me give you an example.

0 Likes 0 ·
Kyle Y avatar image Kyle Y CSN commented ·
2019-09-05 01:23:14
the above is the string. I need to convert DateTime in the same format. Thank you.
0 Likes 0 ·

1 Answer

Steven Hamoen avatar image
0 Likes"
Steven Hamoen answered

@BJ C @Kyle Y

This is not the correct answer because there is function called "convert" which can convert a string into a datetime. Only issue is that it expects the time before the data (so 01:23:14 2019-09-05) but with the string class this is not very complex.


· 5
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Kyle Y avatar image Kyle Y commented ·

Thank you Steven. I have tried with the following code as you mention, but seems there are still something wrong. IIt's supposed to return 2019. But FlexSim return only 1999. Could you please help to have a look? Thank you.

string dateString="00:59:23 2019-09-05";
double dateNum = convert(dateString, DATE_STR, FS_DATETIME);
DateTime dateObject = DateTime(dateNum);
return dateObject.year;
0 Likes 0 ·
capture.jpg (44.3 KiB)
Steven Hamoen avatar image Steven Hamoen Kyle Y commented ·

@Kyle Y

There are 2 remarks here:

1. First you are not converting from a DATE_STR but from a DATETIME_STR

2. Make sure that the string matches the settings in FlexSim concerning the time and date notation.

1 Like 1 ·
Kyle Y avatar image Kyle Y Steven Hamoen commented ·

Thank you Steven. Seems the Datetime_str should in this format: "8:00:00 AM Fri 26 Aug 2016"? Am I correct?

0 Likes 0 ·
Show more comments
Show more comments