SQL Server CE date stored in string : how to compare -
i have database in which, see dates stored in form of strings. possible me compare date (in form of string ) in query?
for eg. column date1
stores 09-11-1992 00:00:00
, date2
stores 22-11-1992 00:00:00
would sensible execute query follows:
select * tablename date1 > "06-11-1992 00:00:00";
if strings in recognizable format, should able cast them datetimes , compare.
select * tablename cast(date1 datetime) > cast('06-11-1992 00:00:00' datetime)
however, i'd recommend iso 8601 format dates. here's 1 possibility:
cast('1992-11-06t00:00:00' datetime)
i'm assuming dd-mm-yyyy here because of date2
example.
just sure know day , month. strings same format , in-line regional settings.
be careful: may have set date format right output data:
set dateformat dmy select cast('06-11-1992 00:00:00' datetime) -- returns 1992-11-06 00:00:00 set dateformat mdy select cast('06-11-1992 00:00:00' datetime) -- returns 1992-06-11 00:00:00
Comments
Post a Comment