Results 1 to 6 of 6

Thread: quick "the Date" question

  1. #1

    Thread Starter
    Addicted Member GenocideOwl's Avatar
    Join Date
    Jul 2006
    Location
    Ohio
    Posts
    144

    quick "the Date" question

    VB Code:
    1. M = Month(TheDate)
    2.     D = Day(TheDate)
    3.     Y = Year(TheDate)

    ok, when the user doesn't unput the date I have these run
    well my question is on the "year" command, will that be the full "2006" or just "06" and if it is the full 2006 then should I just use the "y=y-2000" or is there a way to make it only give the last two?

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: quick "the Date" question

    It will return 2006. Subtracting 2000 from 2006 would give you 6 and not 06. Since the Year function returns an Integer it will not contain leading zeros. But it all depends on what you want to do with the year, you can use the Format function to display it in any form you like.

  3. #3

    Thread Starter
    Addicted Member GenocideOwl's Avatar
    Join Date
    Jul 2006
    Location
    Ohio
    Posts
    144

    Re: quick "the Date" question

    when taking a value to display it, in say a listview, what format call would I make to force it to show "06"

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: quick "the Date" question

    Let me first ask you how you have declared the Y, M, and D variables? Using todays date would give M the value of 7, not 07.

    Please also tell me exactly how you want the date to be displayed. Is there a special reason for splitting up the year, month, and day? I mean should they be displayed in different columns of a ListView, instead of together?

  5. #5
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: quick "the Date" question

    The date stuff aside, to format a number with exactly two digits, with a leading zero if necessary, you would use:
    Format$(The_Number, "00")
    "It's cold gin time again ..."

    Check out my website here.

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: quick "the Date" question

    What Bruce showed above is correct. However why I asked all questions before giving you that answer is because the Format function returns a string while the Year, Month, and Day functions returns an integer. So you need to declare the variable of the correct type. If you want to handle the date parts as strings you can just as well use the following code instead of using the Year, Month, and Day functions.
    VB Code:
    1. Y = Format$(theDate, "yy")
    2. M = Format$(theDate, "mm")
    3. D = Format$(theDate, "dd")
    But for the above to work properly the Y, M, and D variables should be declared as strings.

Posting Permissions

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



Click Here to Expand Forum to Full Width