VB6.0 Date Format
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: VB6.0 Date Format

  1. #1
    Join Date
    Jun 2008
    Posts
    2

    Re: VB6.0 Date Format

    i have create two text boxes and a command buttom. in text1 i put 01/06/2008. i want in text2 it will display 01-may-2008. but it is showing 06-jan-2008. please help...

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: VB6.0 Date Format

    [ Split thread ]
    Please do not post in old threads.

  3. #3
    Join Date
    May 2008
    Posts
    224

    Re: VB6.0 Date Format

    Quote Originally Posted by sanjib294
    i have create two text boxes and a command buttom. in text1 i put 01/06/2008. i want in text2 it will display 01-may-2008. but it is showing 06-jan-2008. please help...
    ? So you put in Jan 6 and you want it to display May 1 ?

    If you are trying to modify the date then you need to give us a clue as to how you are trying to do it and what you are trying to accomplish.

    btw May 1st would be written as 5/1/2008
    Last edited by WillAtwell; June 16th, 2008 at 07:29 AM.

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,961

    Re: VB6.0 Date Format

    use DateAdd() to get the correct date in text2
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jun 2008
    Posts
    2

    Lightbulb Re: VB6.0 Date Format

    i want to insert date from text box. suppose i have put text1 as 01/05/2008. i want it should be posted like 01-may-2008. but it is showing 05-jan-2008. is there any option to do so. But whenever i am trying to insert sysdate it is showing correctly.........Pls help

  6. #6
    Join Date
    Mar 2007
    Location
    Pune
    Posts
    26

    Re: VB6.0 Date Format

    try this

    Code:
    Private Sub Command1_Click()
        Text2.Text = Format(Text1.Text, "dd-MMM-yyyy")
    End Sub
    Framework 1.1
    Windows application Development Using VB.Net

    Visual Basic 6.0 and Crystal Reports

  7. #7
    Join Date
    May 2008
    Posts
    224

    Re: VB6.0 Date Format

    Quote Originally Posted by sanjib294
    i want to insert date from text box. suppose i have put text1 as 01/05/2008. i want it should be posted like 01-may-2008. but it is showing 05-jan-2008. is there any option to do so. But whenever i am trying to insert sysdate it is showing correctly.........Pls help
    Well if I understand you correctly it sounds like you are either entering the date in the format of Day-Month-Year or your system is set to that format and you are entering Month-day-year. Either way the result is that the day and the month are reversed in your second field.

    If you display the date using the date statement how is it displayed? mm/dd/yyyy or dd/mm/yyyy? WHich ever it is you need to use this format when entering a date or change the settings to the format you want to use.

  8. #8
    Join Date
    Dec 2006
    Location
    Pune, India.
    Posts
    579

    Re: VB6.0 Date Format

    Use this:

    Code:
        Dim splt() As String
        splt = Split(Text1.Text, "/")
        Text2.Text = Format(DateSerial(splt(2), splt(1), splt(0)), "dd-MMM-yyyy")

    DateSerial() will return the date in system date format, hence no worry!




    Riyaz

  9. #9
    Join Date
    May 2008
    Posts
    224

    Re: VB6.0 Date Format

    Quote Originally Posted by Shaikh.Riyaz.a
    Use this:

    Code:
    Dim splt() As String
    splt = Split(Text1.Text, "/")
    Text2.Text = Format(DateSerial(splt(2), splt(1), splt(0)), "dd-MMM-yyyy")

    DateSerial() will return the date in system date format, hence no worry!




    Riyaz
    Seems like a waste of code.. If the user is entering a date in the first field then it is a simple matter of formatting it in the second field without need of calling anything other than the format.

    The thing is that the date has to be entered in the format that is expected just as in the code above if the date is not entered exactly as expected it will not return the correct results.

    Not that it is a big deal but there is no need to write the code to parse out the first text box but rather a need to determine the correct format for entering the date.

  10. #10
    Join Date
    Dec 2006
    Location
    Pune, India.
    Posts
    579

    Re: VB6.0 Date Format

    Quote Originally Posted by WillAtwell
    Seems like a waste of code.. If the user is entering a date in the first field then it is a simple matter of formatting it in the second field without need of calling anything other than the format.
    Have your ever tried changing the regional settings for date?????

    Quote Originally Posted by WillAtwell
    The thing is that the date has to be entered in the format that is expected just as in the code above if the date is not entered exactly as expected it will not return the correct results.
    For exact output, there must be exact input and hence people write
    long validation codes for GUIs.

  11. #11
    Join Date
    Mar 2006
    Posts
    16

    Smile Re: VB6.0 Date Format

    This takes a normal date format and converts it to serial number.

    Dim intYear As Integer
    Dim intMonth As Integer
    Dim intDay As Integer
    Dim lngSerial As Long
    Dim strNewDate As String
    Dim datDate As Date

    datDate = CDate("01/05/2008")
    intYear = Year(datDate)
    intMonth = Month(datDate)
    intDay = Day(datDate)

    lngSerial = DateSerial(intYear, intMonth, intDay)

    This converts a long integer representing a valid date into an accepted date format.

    strNewDate = CDate(Format$(lngSerial, "dd-MMM-yyyy"))

    Good luck.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center