Solved

Format of date stored as text compared to date() => problem with month

Posted on 2014-01-29
4
439 Views
Last Modified: 2014-01-29
I'm using format to arrange a date time stored as text:

Format(Mid([CUSTOM_FIELD],5,2) & "/" & Mid([CUSTOM_FIELD],7,2) & "/" & Left([CUSTOM_FIELD],4),"mm/dd/yyyy")

so that I can then use date() to work out data from yesterday date()-1

The trick is that my formating creates a month as 2 digits always and date() will return the month as a single digit creating a situation where 01/28/2014 and 1/28/2014 are not recognized as the same.

I'm wondering what I can do with this to correct for this:

WHERE (((Format(Mid([CUSTOM_FIELD],5,2) & "/" & Mid([CUSTOM_FIELD],7,2) & "/" & Left([CUSTOM_FIELD],4),"mm/dd/yyyy"))=Date()-1));
0
Comment
Question by:ghettocounselor
[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
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39817826
Try this (compares both sides using the same format):

WHERE (((Format(Mid([CUSTOM_FIELD],5,2) & "/" & Mid([CUSTOM_FIELD],7,2) & "/" & Left([CUSTOM_FIELD],4),"mm/dd/yyyy"))=Format(Date()-1),"mm/dd/yyyy)");

Open in new window



Or if your text field is a standard/valid date format:

WHERE CDate([CUSTOM_FIELD])  = dateadd("d", -1, Date())
0
 

Author Closing Comment

by:ghettocounselor
ID: 39817850
Sweet, thanks for quick response.
Notes:
Needed one more paren after format
Format((Date()-1),"mm/dd/yyyy")
0
 
LVL 32

Expert Comment

by:awking00
ID: 39817876
It appears that your "dates" are stored as text in a 'yyyymmdd' format, so it might be easier to convert date() - 1 to text to do the compare. This only works for that format since any comparison will be based on ascii values.
where custom_field = format(date() - 1,"yyyymmdd")

A good example why you should NEVER store dates as anything other than date/time datatypes if you need to perform any kind of data math.
0
 
LVL 32

Expert Comment

by:awking00
ID: 39817890
Be careful! ASCII comparisons can produce some unwanted results. For example,
01/15/2014 will come before 02/15/2013. The reason I said you can get away with yyyymmdd formats.
0

Featured Post

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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