how to use DateTime class

how to use DateTime class

kyle_y
Not applicable
47 Views
9 Replies
Message 1 of 10

how to use DateTime class

kyle_y
Not applicable

[ FlexSim 19.0.0 ]

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 .
Accepted solutions (1)
48 Views
9 Replies
Replies (9)
Message 2 of 10

supportPHJ4A
Observer
Observer

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
Message 3 of 10

kyle_y
Not applicable
2019-09-05 01:23:14
the above is the string. I need to convert DateTime in the same format. Thank you.
0 Likes
Message 4 of 10

SCHamoen
Advisor
Advisor
Accepted solution

@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.


0 Likes
Message 5 of 10

kyle_y
Not applicable

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.22585-capture.jpg

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
Message 6 of 10

SCHamoen
Advisor
Advisor

@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.

Message 7 of 10

kyle_y
Not applicable

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

0 Likes
Message 8 of 10

SCHamoen
Advisor
Advisor

@Kyle Y The format is depending on what you have defined in your model settings. That was my 2nd remark. Here is the setting where you have to look:

22677-modelunits.png

Message 9 of 10

Jacob_Gillespie
Autodesk
Autodesk

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

Message 10 of 10

kyle_y
Not applicable

I got that, it does works. Thank you so much.

string dateString="00:59:23 2019/9/6";
double dateNum = convert(dateString, DATETIME_STR, FS_DATETIME);
DateTime dateObject = DateTime(dateNum);
return dateObject.year;
0 Likes