none
convert a date to the default dateformat RRS feed

  • Question

  • Greetings,

    in MS-Project in the Options is it possible to define the format of a date.

    Now I need a function in VB.NET that return a string that representive the format of the MS-Project settings:

    e.g.

    Date is 19. April 2013

    The Setting is "MM/DD/YYYY": ConvertDate(Date) => "04/19/2013"

    The Setting is "YYYY-MM-DD": CovertDate(Date) => "2013-04-19"

    Thank you!

       Michael

     

    Thursday, January 2, 2014 12:13 AM

Answers

All replies

  • Michael,

    I'm not quite sure exactly what you are trying to do but the GetField function will return the formatted date. For example, let's say the Start date of the first task is 1/1/14. If the general date option is set to show MM/DD/YY, then

    Activeproject.Tasks(1).GetField(pjTaskStart) will give 1/1/14

    If the general date option is set to show MM/DD/YYYY then the above will give 1/1/2014

    If the general date option is set to show January 1, 2014 then the above will give January 1,2014.

    And as far as I know, there is no way to read the general date option setting. It can only be inferred by using the above syntax.

    Does that answer your question?

    John

    Thursday, January 2, 2014 2:10 AM
  • There is a application.DefaultDateFormat property

    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    Thursday, January 2, 2014 6:11 AM
    Moderator
  • Rod,

    Thanks, I missed that one. Is there a table that decodes what the result actually represents?

    John


    Thursday, January 2, 2014 4:48 PM
  • Hello Rod,

    I have tried this Mesagebox, but an exeption occured:

    MsgBox(FormatDateTime(CType(Allg.Anw.ActiveProject.StatusDate, Date), Allg.Anw.DefaultDateFormat))
    
    "Allg.Anw" is the application

    Have you an idea?

    Thank you!

       Michael

    Thursday, January 2, 2014 9:58 PM
  • The default project date format is a number and the FormatDateTime method needs a string such as "mmm d yyyy"

    I think you need to use a Select Case statement to translate the Project.DefaultDateFormat number to a suitable string.


    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    • Marked as answer by Michael-Markus Tuesday, January 7, 2014 12:35 PM
    Saturday, January 4, 2014 12:20 AM
    Moderator