Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Make a date string to be stored (A2K2)

    Hi,
    I have some code that stores a date:
    rstWO!wo_start_date = Format(Me.txtst, "dd-mmm-yyyy")

    I also need to put a time on the end of this such that the date looks something like this:
    "03-02-2003 08:00"

    How do you do this so that the item is stored as a correct date?

    Thanks,
    Mark

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Make a date string to be stored (A2K2)

    I presume you are working with a Date/Time field - so your statement should look like:
    <font color=blue> rstWO!wo_start_date = Format(Me.txtst, "dd-mmm-yyyy hh:nn")</font color=blue>
    That will give you a 24-hour time format. There are other options shown in the Help file under "Format Property - Date/Time Data Type. Note that some aspects of this may be affected by Regional Settings Properties.
    Wendell

  3. #3
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make a date string to be stored (A2K2)

    Thanks Wendell,
    Sorry for not being clearer. What I need to do is create a date/time string with the time of 08:00 all of the time. The start date is selectable and the time is always 08:00. So, I need to store in the format you have stated but I need to make sure that windows sees it as a real date.

    Thanks,
    Mark

  4. #4
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make a date string to be stored (A2K2)

    dim dtTemp as Date
    dtTemp=Format(Me.txtst,"dd-mmm-yyyy")
    dtTemp=dtTemp+(1/3)
    rs.("MyDateField").value=dtTemp

    Of course, you should haven't use the format command, to enforce a date. Just set the textbox to be a date format. 8 am, is one third of a day, so it is probably the easiest way to set the time at eight, is to just add 1/3.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Make a date string to be stored (A2K2)

    Actually, since the desired time is always 8 AM, you could just do it this way:

    rs.("MyDateField").value=CDate(Format$(Me.txtst, "dd-mmm-yyyy") & " 08:00")
    Charlotte

  6. #6
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make a date string to be stored (A2K2)

    I wonder which way is faster...I would bet dealing with the Time as a number, versus a string is faster, since it ends up as a number anyways.

    Of course there are usually 50 ways to make the deal when dealing with dates and times.

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Make a date string to be stored (A2K2)

    Unless you're doing it in a query, the difference in speed is likely to be unnoticeable anyhow. Handling the date as a number is probably faster, since numeric processing always is, but faster is relative. I can't count in milliseconds anyhow, can you? <img src=/S/starstruck.gif border=0 alt=starstruck width=15 height=15>
    Charlotte

Posting Permissions

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