DateFormat,Date,SQL

imfarhan

Board Regular
Joined
Jan 29, 2010
Messages
123
Office Version
  1. 2016
Platform
  1. Windows
Hi All,
I would like to run the following query using date range
Start Date = 01/10/2010 dd/mm/yyyy
End DAte = 31/03/2011 & 23:59:59 dd/mm/yyyy

When I run the Option-1 one using "Parameters" its run ok

Option-1
WHERE (((AdmitDate)<=DateAdd("d",1,[End Date]))
AND ((DischDate)>=DateAdd("d",-28,[Start Date]))

Option-2 (Problem)
When I run the follwoing query it doesn't bring more rows which I'm expecting

AND ((DischDate)>= DateAdd("d",-28,format("01/10/2010","dd/mm/yyyy"))
And (AdmitDate)<=DateAdd("d",1,Format("31/03/2011","dd/mm/yyyy") & " 23:59:59")

I think its the format problem even I tried using # using American format still the same problem mm/dd/yyy. My System|ControPanel|Regional setting is UK i.e dd/mm/yyyy

Thanks for you help
Regards
F
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Why are you using the Format function for the dates in the second example?

Apart from that you should have a look at the Between operator if the criteria is a date range.
 
Upvote 0

Forum statistics

Threads
1,215,125
Messages
6,123,193
Members
449,090
Latest member
bes000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top