problem in displaying current date using label

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adhoc
    New Member
    • Mar 2008
    • 1

    problem in displaying current date using label

    hai guys..

    i'm having prob regarding displaying current date using label..
    i'm using this code:

    lblCurrTime.Tex t = Format$(Now, "dd mm yy")

    the output is:

    14 32 08

    14 is day
    32 is month..why is this happen?
    08 is year..

    plz help me..
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by adhoc
    hai guys..

    i'm having prob regarding displaying current date using label..
    i'm using this code:

    lblCurrTime.Tex t = Format$(Now, "dd mm yy")

    the output is:

    14 32 08

    14 is day
    32 is month..why is this happen?
    08 is year..

    plz help me..
    I have no idea. Try using Format instead of Format$, because you are not working with strings, but with dates.

    May be you should be changing the label's caption instead of the label's text, but that depends on the version of VB.

    Other than that, your code seems perfect to me, and even using Format$, it should be working fine.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      My guess would be that you're getting minutes rather than month. Probably because of the spaces (dates are more usually delimited with dashes, dots or slashes). Could you try using "mmm" instead?

      The date value returned by Now actually contains both date and time, so if you think about it, "mm" is a bit ambiguous - it could mean months or minutes. In connection with a year or day, it's fairly obvious what it means. But taken on its own, it could be either. So it looks as though maybe the Format() function isn't taking the "yy" or "dd" into account. If you use something unambiguous such as "mmm", you should avoid the pitfall.
      Last edited by Killer42; Mar 14 '08, 12:55 AM.

      Comment

      Working...