CString to CTime
-
Could anyone tell me if there's an easy way to convert date/time from CString to CTime? I would, for example, like to convert the string "2001-07-26 14:37:00" to a CTime object. I could do this using string operations to parse out the year, month, etc.. This, however, does not feel like a good solution since it's not very flexible. I would have to include several if-statements in the parsing to be able to handle dates on other formats, like "2001-07-26", "2001-07-26T14:37", etc. What would make me very happy is if there's a way to use formatting string to specify the format of the input. Like when I convert a CTime object to a CString using Format() with formatting codes like %Y, %m, etc. Maybe somebody has written a class, derived from CTime, that could handle this? Jimmy Ehrnström
-
Could anyone tell me if there's an easy way to convert date/time from CString to CTime? I would, for example, like to convert the string "2001-07-26 14:37:00" to a CTime object. I could do this using string operations to parse out the year, month, etc.. This, however, does not feel like a good solution since it's not very flexible. I would have to include several if-statements in the parsing to be able to handle dates on other formats, like "2001-07-26", "2001-07-26T14:37", etc. What would make me very happy is if there's a way to use formatting string to specify the format of the input. Like when I convert a CTime object to a CString using Format() with formatting codes like %Y, %m, etc. Maybe somebody has written a class, derived from CTime, that could handle this? Jimmy Ehrnström
You can use COleDateTime::ParseDateTime( string ) to convert the string into the underlying DATE object. If you don't like to use COleDateTime objects and need the CTime object, you would have to convert between the two. Create a tm structure and populate the structure from the COleDateTime object and then using mktime( tm ) assign the result to the CTime object.
-
Could anyone tell me if there's an easy way to convert date/time from CString to CTime? I would, for example, like to convert the string "2001-07-26 14:37:00" to a CTime object. I could do this using string operations to parse out the year, month, etc.. This, however, does not feel like a good solution since it's not very flexible. I would have to include several if-statements in the parsing to be able to handle dates on other formats, like "2001-07-26", "2001-07-26T14:37", etc. What would make me very happy is if there's a way to use formatting string to specify the format of the input. Like when I convert a CTime object to a CString using Format() with formatting codes like %Y, %m, etc. Maybe somebody has written a class, derived from CTime, that could handle this? Jimmy Ehrnström
VarDateFromStr