Results 1 to 9 of 9

Thread: Date Problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118
    I have been using thi9s code to update a field, and until today it worked fine. Can someone try this code and tell me if there is a problem. I get 2/1/1368 as the return value.
    Code:
    Command1.Click()
    Dim dDate
    dDate = Format(Now, Date)
    Text1.Text = dDate
    End Sub
    Kokopeli
    VB6 SP3

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    Angry why don't you just

    check your system date or just use
    Code:
    cdate(now)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    just wondering

    I changed the code in my program, I was just wondering why that code worked fine for five months and today it went crazy.
    Kokopeli
    VB6 SP3

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I think it's the best (well not the best but it works for me) to use
    Code:
    Dim dDate As String
    dDate = Date
    Text1.Text = dDate
    Always declare your variable with a specific data-type, otherwise it uses a variant wich consumes lots of memory.

    from the VB helpfile:
    This example shows various uses of the Format function to format values using both named formats and user-defined formats. For the date separator (/), time separator (, and AM/ PM literal, the actual formatted output displayed by your system depends on the locale settings on which the code is running. When times and dates are displayed in the development environment, the short time format and short date format of the code locale are used. When displayed by running code, the short time format and short date format of the system locale are used, which may differ from the code locale. For this example, English/U.S. is assumed.

    MyTime and MyDate are displayed in the development environment using current system short time setting and short date setting.

    Code:
    Dim MyTime, MyDate, MyStr
    MyTime = #17:04:23#
    MyDate = #January 27, 1993#
    
    ' Returns current system time in the system-defined long time format.
    MyStr = Format(Time, "Long Time")
    
    ' Returns current system date in the system-defined long date format.
    MyStr = Format(Date, "Long Date")
    
    MyStr = Format(MyTime, "h:m:s")	' Returns "17:4:23".
    MyStr = Format(MyTime, "hh:mm:ss AMPM")	' Returns "05:04:23 PM".
    
    MyStr = Format(MyDate, "dddd, mmm d yyyy")	' Returns "Wednesday,
    	' Jan 27 1993".
    ' If format is not supplied, a string is returned.
    MyStr = Format(23)	' Returns "23".
    
    ' User-defined formats.
    MyStr = Format(5459.4, "##,##0.00")	' Returns "5,459.40".
    MyStr = Format(334.9, "###0.00")	' Returns "334.90".
    MyStr = Format(5, "0.00%")	' Returns "500.00%".
    
    MyStr = Format("HELLO", "<")	' Returns "hello".
    MyStr = Format("This is it", ">")	' Returns "THIS IS IT".
    [Edited by Jop on 10-02-2000 at 12:48 PM]
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    I get the same as you using your code.
    It must have something to do with the format command
    using a registered word for format. I don't know.

    There is no need to use a variable at all.
    Just do this:

    Text1 = Format(Date, "yyyy/mm/dd")
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I even get an error upon trying this
    Code:
    Dim dDate
    dDate = Format(Now, Date)
    Text1.Text = dDate
    (Runtime error 13: Type mismatch), using VB5

    So I suggest using one of my or hesaidjoe's methods.

    There is no need to use a variable at all.
    Maybe there is ofcourse, when he later want to recall that date when saving stuff or something, but I assume you knew that so this was one of my useless replies, no hard feeling wayne!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    It works for me

    that code will run on mine, just gives me a wierd date. I have changed my code, dDate = Date, just couldn't figure out why the date was so weird. In my program I had dDate typed, just used variant for the example.
    Kokopeli
    VB6 SP3

  8. #8
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    As per my post above..yes the code runs but it gives me the same as you 1368 for year. It appears to me to be a problem with fomatting using a vbReserver Word.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  9. #9
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    As per my post above..yes the code runs but it gives me the same as you 1368 for year. It appears to me to be a problem with fomatting using a vbReserver Word.
    yeah think that's it, but pretty strange/dumb they didn't change it in VB6, because they were aware of the problem because I (with VB5) get actually an error, so they changed it in VB6 but not the good way
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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