Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format of date/time records 1

Status
Not open for further replies.

jjmclell

Technical User
Aug 10, 2007
34
CA
Hi there,

I have a date/time field on my form and I'm having a problem where the access keeps adding seconds to my time entry. For example, if I enter a date and time of:

2007/04/10 3:52 PM

Access changes it to this when I switch the focus on the form:

2007/04/10 3:52:00 PM

Is there anyways to format the date/time data type so it doesn't do this?

jjmclell
 
If I am remembering the formats for dates rigth cold putting the following in the format of the control or field definiation on the format property should work.

yyyy/mm/dd h:nn A

I may not be remembering AM and PM correctly, so you might have to lookup the date formatting in help.
 
Thanks, that is what I have to do I've discovered...however, I can't just put it into the format field in the properties box b/c you can only select default formats from a drop down menu. This means I have to code it in and I've found the Format method but I'm having trouble getting it to work. Here are my questions:

1) Do I code the format for the text box as an event?
2) Format(expression,[ format,[ firstdayofweek,[ firstweekofyear]]]) ...how does this syntax work? If I want to format the input as mm/dd/yyyy h:nn A, what would the code look like? I keep getting errors no matter what I try.

Thanks,

jjmclell
 
Just because there is a drop down doesn't necessarily mean you can't type into it. You can put that format into the format property of a textbox and it will format the data as specified.

However, to force input to be entered a certain way you would want to specify an input mask. I would recommend against it for a date.

If you specify the format and I entered

January 5, 2007 18:00:15

Then the text box would change the screen display to...

01/05/2007 6:00 PM

Using an input mask, I would have to enter it exactly as you specified. I find that using input masks on date and time fields eventually ends up with a user complaining about it. Note in my example, I did enter seconds so you may need an afterupdate event or validation rule to keep seconds out of the input.

Perhpas of validation rule of
Code:
Second (DateTimeField) = 0

Or if you just wanted to drop the seconds in the afterupdate you could use the second funtion with the datediff function to get the desired result.

 
Thanks a lot. Your method of typing the format into the format field in the properties box is the right way to do it. I did try it yesterday and couldn't get it to work but I was probably doing something stupid like typing the date format into the italics property. Thanks again,

jjmclell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top