Comparing SQL Server and User dates

F

F@yy@Z

Hi

I have posted the question few days back about problem in inserting the
dates in SQL server and thankful to them who replied.
That was solved and this is a nice solution.
http://www.aspfaq.com/show.asp?id=2023

Now I am facing another problem.

I have to get data between two dates. That dates user has to provide and in
a specific format like dd/mm/yyyy if SQL server date format is same then no
problem but if SQL server format mm/dd/yyyy then I am getting error.

Please advise how to solve this problem.

Kind Regards
 
C

CJM

Three obvious solutions are:

- To publish the format that you expect the dates to be given in, so the
user knows what is expected of them.
- Use some sort of calendar script so there can be no ambiguity
- Break the date in separate Day, Month and Year fields (with drowdowns
perhaps)

I use the first idea for most intranet apps, and the second for most web
apps.

Chris
 
F

F@yy@Z

- To publish the format that you expect the dates to be given in, so the
user knows what is expected of them

In this option problem is I am not sure about the system date it can be
dd/mm/yyyy or mm/dd/yyyy and when comparing it gives error.
- Use some sort of calendar script so there can be no ambiguity

I am already using calandar for input and this calander always provide
dates in dd/mm/yyyy what ever the system format and again if system format
is not dd/mm/yyyy
- Break the date in separate Day, Month and Year fields (with drowdowns
perhaps)

This solution is better but in my SQL Query I have to get date as YYYYMMDD
format so comapring will not be a problem. But Only comes when I am
adding/substarcting days from this date.

Any how thanks for your help.

Regards
 
A

Aaron [SQL Server MVP]

In this option problem is I am not sure about the system date it can be
dd/mm/yyyy or mm/dd/yyyy and when comparing it gives error.

I don't know what you mean. Since you can control input by not letting a
user type a date in (pick from a dropdown or a calendar control), and since
you can control output by formatting the date yourself, I don't know where
the problem would come in.
I am already using calandar for input and this calander always provide
dates in dd/mm/yyyy

If you can't specify the format and can't fix it, use a different calendar.
 
M

Mark Schupp

Take the value from your calendar (which you say is always dd/mm/yyyy) and
reformat it to yyyy-mm-dd before converting from a string to a date. That
way it will not matter what the server system date is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top