Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access 2016 date picker changing date format

Posted on 2016-08-31
6
Medium Priority
?
861 Views
Last Modified: 2016-10-07
I am running Access 2016 in Windows 10.  I have a form with a text box that displays dates.  It is set to show the date picker.  The text box Format property is set to Long Date. In the Load event for the form, the text box is set to Format(Now(), "Long Date") and all displays well when it first opens.  However, when I use the date picker to select a date, it displays as the correct long date but the Me.textbox.value property has the date in a dd/mm/yyyy format.  This causes a problem when I use this value for a date comparison with database table dates that are stored in a date field, which compare as mm/dd/yyyy.  If I pick today's date to find in the database, the database date will be 08/31/2016 and the me.textbox.value will be 03/08/2016.  I determined this in debug mode.

I tried Format(Me.textbox.value, "mm/dd/yyyy") but still got 03/08/2016.  The only way to get the right date is Format(Me.textbox.value, "dd/mm/yyyy")!  That gives me 08/31/2016, which is crazy.

What is going on here?

Thanks.
0
Comment
Question by:McLeanIS
6 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 41778251
What does the format specification of "dd-Mmm-yyyy" produce?
0
 
LVL 40

Accepted Solution

by:
PatHartman earned 1000 total points (awarded by participants)
ID: 41778303
STOP formatting the dates.  Once you format a date, it becomes a text field and then it acts like a text field rather than like a date field.  Dates are stored internally as double precision numbers.  The integer part is the number of days since Dec 30, 1899 and the decimal is the fraction of the day since midnight.

As long as you don't use the Format() function, your dates will stay as DateTime data type and compares will work as you expect.

Use the format property of the control to specify how the date should be formatted for human viewing.

print now()
8/31/2016 11:48:59 AM
print cdbl(#8/31/2016 11:48:59 AM#)
 42613.492349537
print DateAdd("d", 42613, #12/30/1899#)
8/31/2016

The cdbl() version is how the date is stored internally.  Dates are stored this way because it makes arithmetic and logical operations simpler and does not require Access to do a lot of conversions behind the scenes.
0
 
LVL 52

Assisted Solution

by:Gustav Brock
Gustav Brock earned 500 total points (awarded by participants)
ID: 41778710
In the Load event for the form, the text box is set to Format(Now(), "Long Date")
Then you convert the date value to a string.
So set the value to a date value:

    Me!textbox.Value = Now

or, as you don't need the time, rather:

    Me!textbox.Value = Date

/gustav
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 22

Assisted Solution

by:crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access earned 500 total points (awarded by participants)
ID: 41780414
adding on to Pat's comment:
the Format function always returns a string (which is text) and no longer a date/time data type

and repeating: to retain the date/time data type, use the Format PROPERTY to change the display, not the Format function
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 41800508
The questioneer is non-responding, so I vote for a delete.

/gustav
0
 
LVL 22
ID: 41833315
poster seems to have issues with data type
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question