Solved

Access 2016 date picker changing date format

Posted on 2016-08-31
6
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 35

Expert Comment

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

Accepted Solution

by:
PatHartman earned 250 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 50

Assisted Solution

by:Gustav Brock
Gustav Brock earned 125 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Assisted Solution

by:crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access earned 125 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 50

Expert Comment

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

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

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reports issues going from Access 2003 to Access 2013 14 71
Conditional Format if Between Dates 9 45
GA Ribbon creator 9 64
Outlook mail to Access 8 28
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

739 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