Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I am generating a report from the UI which involves performing a query like where currrentdate between date1 and date2.

The application is being hosted for an indian company. The database by default stores it in mm/dd/yy.

But the customer prefers to see the format dd/mm/yy when he enters the dates in the UI and doesnt care about the locale in the sql server.

By default its set to US, which is fine..but how to do work with it to query accurately?.
Can someone help me here to help set up the database column with proper locale and guide me through the sql query.

I am asking the sql date column is by default- mm/dd/yy.

The where clause of the query should be like-

dd-mm-yy format?
WHERE currentDate between '1-1-2013' AND '31-12-2014'
OR
mm/dd/yy format?.
WHERE currentDate between '1/1/2013' AND '12/31/2014'
OR
Posted
Comments
Per Söderlund 18-Jul-14 0:29am    
Isn´t this handled by ADO.net if you use SqlParameters with your queries?

Try this. It doesenot use any seperator. This also helps in avoiding mm/dd and dd/mm erros.

112 format is yyyymmdd.

WHERE convert(currentDate,112) between '20130101' AND '20141231'
 
Share this answer
 
v2
Here is your solution

SQL
where convert(varchar(20),currentDate ,103) between '1/1/2013' AND '12/31/2014'


You have to convert your date to dd/mm/yyyy format, 103 gives dd/mm/yyyy format

for more datetime format command you can refer Convert function in sql[^]
 
Share this answer
 
use this solution

SQL
WHERE GETDATE() BETWEEN CONVERT(DATE,'01/01/2014') AND CONVERT(DATE,'12/31/2014')
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900