Results 1 to 4 of 4

Thread: Date Format

  1. #1
    New Lounger
    Join Date
    Sep 2013
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Date Format

    Hello,

    This codes generates Month and Year as 12-2013 instead of this i require it as December-2013.
    Code:
        Sub Test()
        Dim strDate As String
        strDate = InputBox("Insert Month & Year for Suject Line MM/YYYY", "Subject Line Date", Format(Now(), "mm/yyyy"))
        If IsDate(strDate) Then
        strDate = Format(CDate(strDate), "mm/yyyy")
        MsgBox strDate
        Else
        MsgBox "Wrong date format"
        Exit Sub

  2. #2
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,638
    Thanks
    115
    Thanked 650 Times in 592 Posts
    Goa,

    Use this line instead:

    strDate = Format(CDate(strDate), "mmmm-yyyy")

    BTW, you will need to replace "exit Sub" with "End If" followed by "End Sub" for the code to run.

    HTH,
    Maud
    Last edited by Maudibe; 2013-12-27 at 07:19.

  3. #3
    New Lounger
    Join Date
    Sep 2013
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello,

    Thanks for helping, And suppose if want to have this October 2013 - December 2013 how do i get that.

    Thanks in advance.

  4. #4
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,638
    Thanks
    115
    Thanked 650 Times in 592 Posts
    Code:
    Sub Test()
    Dim strDate1 As String
    Dim strDate2 As String
    strDate1 = InputBox("Insert Start Month & Year for Suject Line MM/YYYY", "Subject Line Date", Format(Now(), "mm/yyyy"))
    strDate2 = InputBox("Insert End Month & Year for Suject Line MM/YYYY", "Subject Line Date", Format(Now(), "mm/yyyy"))
    If IsDate(strDate1) And IsDate(strDate2) Then
    strDate1 = Format(CDate(strDate1), "mmmm yyyy")
    strDate2 = Format(CDate(strDate2), "mmmm yyyy")
    MsgBox strDate1 & " - " & strDate2
    Else
    MsgBox "Wrong date format"
    End If
    End Sub
    Date.png
    Last edited by Maudibe; 2013-12-28 at 16:22.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •