Monday, March 19, 2012

Date issue

I have got an issue with dateformats. When i retrieve a date field from the
sql server it is noted as 02/10/2005 17:40:00. everything fine so far. I
want to compare it to the current time. This doesn't work. When i print the
current datetime i get " 4 Nov 2005 5:40PM". How can i set sql so it returns
the current date as 02/10/2005 17:40:00.
Your help is much appreciated.
Regards Ron WallegieRon Wallegie (wallegie@.planet.nl) writes:
> I have got an issue with dateformats. When i retrieve a date field from
> the sql server it is noted as 02/10/2005 17:40:00. everything fine so
> far. I want to compare it to the current time. This doesn't work. When i
> print the current datetime i get " 4 Nov 2005 5:40PM". How can i set sql
> so it returns the current date as 02/10/2005 17:40:00.
Preferrably you should return datetime value as-is from SQL Server, that
is no convert. The date value is then passed to the client as a binary
value, and the client will format it according to regional settings.
Same thing applies when you pass dates to SQL Server - pass them as
datetime values in parameters, and conversion will be performed by the
client API, again according to regional settings.
If you for some reason must work with date literals in SQL Server, use
the the format YYYYMMDD. This format is safe from different interpretations.
Note that SQL Server does never look at regional settings in Windows,
and has its own settings. And due to legacy, the safe format in Windows,
YYYY-MM-DD is not safe in SQL Server.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||If you just want to get the presentation do display as you specifiied, you
can format it to "print" by converting it to a varchar. Look up CAST and
CONVERT in BoL.
SELECT CONVERT(varchar(10), GetDate(), 101) + ' ' + CONVERT(varchar(8),
GetDate(), 108)
HTH,
John Scragg
"Ron Wallegie" wrote:

> I have got an issue with dateformats. When i retrieve a date field from th
e
> sql server it is noted as 02/10/2005 17:40:00. everything fine so far. I
> want to compare it to the current time. This doesn't work. When i print th
e
> current datetime i get " 4 Nov 2005 5:40PM". How can i set sql so it retur
ns
> the current date as 02/10/2005 17:40:00.
> Your help is much appreciated.
> Regards Ron Wallegie
>
>

No comments:

Post a Comment