How to convert date from string to DateTime ?

How to convert date from string to DateTime ?

nicolas_membrez4BM5L
Enthusiast Enthusiast
171 Views
3 Replies
Message 1 of 4

How to convert date from string to DateTime ?

nicolas_membrez4BM5L
Enthusiast
Enthusiast

[ FlexSim 22.1.0 ]

I want to convert this date format (string) to DateTime in order to get the dayoftheweek() and hour(). I saw that there is a convert function, but I don't understand how to use it. Can you help me?


string dateTime_str = "15.03.2019 09:37";

DateTime DT = convert(dateTime_str, DATETIME_STR,FS_DATETIME);

return DT;

0 Likes
Accepted solutions (1)
172 Views
3 Replies
Replies (3)
Message 2 of 4

jason_lightfootVL7B4
Autodesk
Autodesk
Accepted solution

Try this:

string dateTime_str = "15.03.2019 09:37";
DateTime dt=DateTime(dateTime_str,"%d.%m.%Y %H:%M");
return [dt.dayOfWeek,dt.hour];

The datetime constructor is documented here.

0 Likes
Message 3 of 4

nicolas_membrez4BM5L
Enthusiast
Enthusiast

It works ! Thanks !

where can i find this type of explanation in the help (DateTime(dateTime_str,"%d.%m.%Y %H:%M") ?

0 Likes
Message 4 of 4

nicolas_membrez4BM5L
Enthusiast
Enthusiast
found, thanks a lot !
0 Likes