SQL date comparison

Hello everyone, I would like to compare dates using an Excel file as the Data Base :

Here is the format of my file : (01/29/2023 00:00:00) My excel column is in date format

This is my sql query :

"Select * From [Export$] where [Code] =‘22’ AND [Product Code] NOT IN (‘101748’) AND [MRP] NOT IN (‘091’) AND [Planned Delivery Date] >= "+DateOfTheDay

DateOfTheDay format : 02/03/2023
If I put my date in the same format, I get this error:
image

How can I compare these dates without changing the format of my Excel file?

Hi @DimitriLYR ,

The format of both dates should be the same. As I can see ‘DateOfTheDay’ format is dd/MM/yyyy and
The ‘Planned Delivery Date’ format is dd/MM/yyyy hh:mm:ss.

Please try modifying the format of ‘Planned Delivery Date’ to dd/MM/yyyy before passing it into the query.

Let me know if this works for you.

Cheers!

1 Like

How can I change this without opening my Excel file?

Try changing the ‘DateOfTheDay’ format to dd/MM/yyyy hh:mm:ss and see if its works.

How do I change the format in my SQL query?

image

Have an error message :

image

I just need to allow my query to compare dates with a timestamp. Anyone got a tip?

Hi @DimitriLYR ,

I’m no expert on SQL queries but try the below code and let me know if this works for you,

Select * From [Export$] where [Code] =‘22’ AND [Product Code] NOT IN (‘101748’) AND [MRP] NOT IN (‘091’) AND CAST(Planned Delivery Date AS DATE) >= '+DateOfTheDay'

Also, you can take a reference from the below link.
Comparing Timestamp Dates With Date-Only Parameter in SQL

If this resolves your issue, Then please mark this as the solution to close this thread.

Regards,
Ashutosh Gupta

Hello, this does not work either, I have the same error message:

image

I succeeded! For those who want the solution here : I put the dates between # #build

“Select * From [Export$] where [Code] ='”+Code+“’ AND [Product Code] NOT IN ('”+Product+“‘) AND [MRP] NOT IN (’”+MRP+“') AND [Planned Delivery Date] <= #”+DateOfTheDay+“#”

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.