• Make a date string to be stored (A2K2)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Make a date string to be stored (A2K2)

    Author
    Topic
    #382988

    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

    Viewing 0 reply threads
    Author
    Replies
    • #651420

      I presume you are working with a Date/Time field – so your statement should look like:
      rstWO!wo_start_date = Format(Me.txtst, “dd-mmm-yyyy hh:nn”)
      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.

      • #651447

        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

        • #651454

          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.

          • #651469

            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″)

            • #651472

              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.

            • #651477

              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? starstruck

    Viewing 0 reply threads
    Reply To: Make a date string to be stored (A2K2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: