473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Data Type Mismatch - Converting String To Date and then Comparing To Date()

Hello everyone,

I have been experiencing some errors that I simply haven't been able to resolve on my own. Some background information:

I'm migrating my company's Access database to SQL Server. My boss still wants the reports in Access to work if we need them. I am generating equivalents directly from SQL Server too, but he still wants the Access reports to work.

The Access tables are going to be linked to CSV files generated from the SQL Server. However, once the CSV files are linked to Access, the date values need to be stored as Text data types, since if I try to import the Date fields as Dates, all the date fields get set to #NUM instead of the date.

One of our reports generates a list of orders that have a transaction date from the past 24 hours, so I need to compare the transaction date to the current date (minus a day).

First I convert the text value to a date, and then compare that to the current date.

I'm going to show a simplified query instead of the query I'm actually doing, since essentially I just have to resolve the "Data Type Mismatch" error that I'm getting:

Expand|Select|Wrap|Line Numbers
  1. SELECT id, TransDateTime, CDate(Left(Replace(TransDateTime,"-","/"),19)) AS Formatted
  2. FROM OrdersCopy
  3. WHERE DateValue(CDate(Left(Replace(TransDateTime,"-","/"),10)) )< DateValue(Date())
It doesn't work if I leave out DateValue() as well. I always get a data type mismatch error.

Does anybody know how to get it to properly compare?

Thanks,
-Chris
Dec 24 '14 #1
1 3029
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

You can use the IsDate() function to return the records that are failing to convert to a date to see which ones are causing the data type mismatch.
Dec 24 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jacquo Johnson | last post by:
I am receiving the following error: MS Access Date/Time DBD::ODBC::st execute failed: , , " . "FROM WHERE > '2004/02/01 11:16:16'"; $sth = $dbh->prepare($sqlstatement); $sth->execute ||...
1
by: amitbadgi | last post by:
I am getting the following error while converting an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Data type mismatch in criteria expression. ...
19
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the...
2
by: zoro25 | last post by:
Hi, I'm pretty sure it's a no brainer for some people, but I'm lost... I have a form that I use to filter on a report on Access 2000. I use various criterias in list boxes to filter my report...
5
by: isoquin | last post by:
The below code throws the error: "Data type mismatch in criteria expression" Searching online didn't seem to offer me a solution. Public Sub update_by_EDD(myDate As Date, myMR As String) ...
3
by: vishwaskothari | last post by:
What is wrong in the following Statement? Dim mydate As Date Format(mydate, "m/d/yy") rs.Open "SELECT * from accounts where date='" & mydate & "';", con, adOpenStatic, adLockOptimistic
3
by: Bruce Lawrence | last post by:
I've got a form that when it opens it prompts the user for 2 peices of information. The Asset and the Date. getasset = InputBox("Enter the Asset Number") If getasset = "" Then Exit Sub Else...
9
by: nixonmg | last post by:
When the Command Button "Notify" is clicked, I am wanting to send out an email to the user with appropriate information in the email (works great), check the "Notified" check box (does not work), and...
2
by: hype261 | last post by:
So I have a SQL Query I am trying to author and it keeps giving me a Data Type mismatch error which I can't seem to see. Exact error message is Data type mismatch in criteria expression. Here is...
6
by: Rob Amor | last post by:
I have 2 queries which have been working for the last 2 or 3 years but last week decided to start giving me a data type mismatch error. Query 1 looks at how many records have been created in the last...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.