none
Custom formatting of dates RRS feed

  • Question

  • Module Module1
        Sub Main()
            Dim rawDates() As Date = {#2010-06-01#, #2010-07-01#, #2010-08-01#}
    
            For i = 0 To rawDates.GetUpperBound(0)
                Console.WriteLine("Date is {0:yyyy/mm}", rawDates(i))
            Next
    
            Console.ReadLine()
    
        End Sub
    End Module

    In the code the date literals are in YYYY-MM-DD format. I want the output of date as 2010/06, 2010/07,2010/08. But the month is coming as 00. Please tell me what is the correct format command to get the desired output?


    Sougata Ghosh

    Friday, July 27, 2018 6:41 AM

Answers

  • Try this:

    Console.WriteLine("Date is {0:yyyy'/'MM}", rawDates(i))

    • Proposed as answer by Alex Li-MSFT Friday, July 27, 2018 7:15 AM
    • Marked as answer by sougata12 Friday, July 27, 2018 7:40 AM
    Friday, July 27, 2018 7:05 AM
  • Hi

    The uppercase and lowercase of m is to distinguish between month and minute, so your letter m must be capitalized.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by sougata12 Friday, July 27, 2018 7:41 AM
    Friday, July 27, 2018 7:20 AM

All replies

  • Try this:

    Console.WriteLine("Date is {0:yyyy'/'MM}", rawDates(i))

    • Proposed as answer by Alex Li-MSFT Friday, July 27, 2018 7:15 AM
    • Marked as answer by sougata12 Friday, July 27, 2018 7:40 AM
    Friday, July 27, 2018 7:05 AM
  • Hi

    The uppercase and lowercase of m is to distinguish between month and minute, so your letter m must be capitalized.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by sougata12 Friday, July 27, 2018 7:41 AM
    Friday, July 27, 2018 7:20 AM