Results 1 to 5 of 5

Thread: datepart code

  1. #1
    Join Date
    Mar 2012

    Unanswered: datepart code

    I would like to change a textbox from a time to a general date with date and time like : 03/03/12 11:00 am. This code is the button we have now that automatically enters time I would like auto date and time. How do I change this (Access 2010)

    Private Sub btnAutoDepart_Click()
    ' Comments :
    ' Parameters : -
    ' Returns : -
    ' Created :
    ' Modified :
    ' --------------------------------------------------------
    On Error Resume Next

    Time_Depart = Format(DatePart("h", Now), "00") & ":" & Format(DatePart("n", Now), "00")

  2. #2
    Join Date
    May 2009
    Hi keitkris,

    The "Now" variable contains the information that you are looking for, so just change:
    Time_Depart = Format(DatePart("h", Now), "00") & ":" & Format(DatePart("n", Now), "00")
    Time_Depart = Now
    You would have to make sure that any field lengths that are dependent upon Time_Depart are updated to allow the extra information, if not already so.



  3. #3
    Join Date
    Mar 2012


    I seem to make things harder than what they are. Thank you Ax that worked, of course.

  4. #4
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    why would you go through such hoops

    the inbuilt access function you are already using gives you the date and time
    for the record
    date() give the current system date
    Time() gives the current system time
    now() gives the current system AND time
    you need to bear in mind that Access / JET stores date time values as rthe number of days since a specific point in time (IIRC 01 Jan 1900)
    Access Date Functions

    so in reality
    Date() gives you the date and TIME of todays date at midnight this morning (IE when the clock resets to 00:00:00
    Time() gives you the current system time but for the first dayin its calendar (effe3ctivley Day 0.

    so that gives you the data
    the rest of it is just down to formatting, which has no bearing on the underlying storage
    so change the format mask for that control to read what ever date format style you wish. to repeat the formattign / style has no impact on the data and vice versa.
    =format (now(), "dd mmm yyyy @ HH:MMS AM/PM")
    Format date and time values - Access -

    the only real issues are when you come to supply date / time values into a db where Access insists on US and occasionally iso date formats
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Mar 2012
    Thank you for the info. I am working with a database created in 95. I am not a DBA but dabble in it. I work for a company that is now taking shipments round the clock instead of just the 8 hours a day as they were in 95 so dates need to reflect 24 hour days with some shipments checking in one day then checking out the next. ( Messed up reporting. ) It was a challenge but I did get it worked out thanks for the instruction.

Posting Permissions

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