Search code examples
c#office-interopms-project

Parse datetime string value of MS Project


I need to retrieve Datetime value of custom fields assigned to Resource. I can retrieve value from custom field as String value with using GetField. This value will be formatted with DefaultDateFormat of MS Project. Thus, the date will be represented like this(example):

"Tue 11/21/23 7:43 AM"

Is there a way to convert String to DateTime based on known PjDateFormat?


Solution

  • The easiest way to deal with an unknown default date format is to change it to what you want and then reset it back for the user. Here is are the basics in vba, translate to c# as necessary.

    Dim CurrentDateFormat As Long
    
    Sub SetDateFormat()
        CurrentDateFormat = Application.DefaultDateFormat
        Application.DefaultDateFormat = pjDate_mm_dd_yy_hh_mmAM
    End Sub
    
    Sub ResetDateFormat()
        Application.DefaultDateFormat = CurrentDateFormat
    End Sub