|
-
Aug 29th, 2005, 08:24 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] SQL Server dates
Hello,
in my web application, i insert use the getDate() function in sql to insert the dates into the database.
They are stored as '2005/07/29 14:16:19'
now i need to select records between 2 dates from the table.
the format the user will select is DD/MM/YYYY
what is the best way to convert this inside my sql statement so that sql server recognises it as yyyy/mm/dd
or do i need to change it in my code?
cheers
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Aug 29th, 2005, 08:44 AM
#2
Re: SQL Server dates
 Originally Posted by Strider
Hello,
in my web application, i insert use the getDate() function in sql to insert the dates into the database.
They are stored as '2005/07/29 14:16:19'
now i need to select records between 2 dates from the table.
the format the user will select is DD/MM/YYYY
what is the best way to convert this inside my sql statement so that sql server recognises it as yyyy/mm/dd
or do i need to change it in my code?
cheers
Take a look at this Link regarding CAST and CONVERT
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 30th, 2005, 06:25 AM
#3
Fanatic Member
Re: SQL Server dates
SQL Server should handle this implicit conversion for you. I use the same thing here, getDate(), and it stores it in the same format. When my users search for records based on date, I don't do any type conversions and in fact, force them to use a MM/DD/YYYY format when they enter their dates.
Chris
Master Of My Domain
Got A Question? Look Here First
-
Aug 30th, 2005, 08:18 AM
#4
Thread Starter
Fanatic Member
Re: SQL Server dates
in my code i have my sql statement as
"SELECT * FROM mytable WHERE DateReceived < Date.Today"
where date.today will be 30/08/2005
but if i use this i get the following error
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
because the 2005 is not a day and is in the place where the day should be
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Aug 30th, 2005, 09:57 AM
#5
Re: SQL Server dates
30/08/2005 is not a valid date for SQL Server, it should be 08/30/2005 instead (it always assumes American date format).
If you can, convert the date to this format.
-
Aug 30th, 2005, 10:00 AM
#6
Thread Starter
Fanatic Member
Re: SQL Server dates
god dharm americans!!!!!!!
i decided to go with stored procedure and pass in a date 30/08/2005 to a datetime variable in the stored procedure and this done the conversion for me to the sql standard of 2005/08/30
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Aug 30th, 2005, 12:19 PM
#7
Re: SQL Server dates
 Originally Posted by Strider
god dharm americans!!!!!!!
But we still Love You
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|