Annelies
Programmer
- Nov 25, 2001
- 72
Hi
The scenario is:
I am storing date information in a database in the format mm/dd/yy, in a char(8) field. (So, a piece of example data might be '01/03/03')
But when I run a report over multiple months (ie, everything from %/01/03 or %/02/03) it does not sort the dates correctly, because (understandly) the database thinks it is sorting strings, not dates. So I get 01/01/03, 01/02/03, 02/01/03, 02/02/03, etc...
So, I think I need to convert the char field into a date, for the purposes of this report.
However, I'm finding that:
SELECT CONVERT(DATETIME, '01/03/03') returns 2003-01-03 00:00:00.000, which the system reads as the 3rd Jan 2003, instead of 1st March 2003.
and if I try to use a 'style' (ie, 103 which is British/French) then I get the following:
SELECT CONVERT(DATETIME, '01/03/03', 103) = Syntax error converting datetime from character string.
Can anyone help? Am I even going about this the right way??
Thanks in advance!
Annelies
The scenario is:
I am storing date information in a database in the format mm/dd/yy, in a char(8) field. (So, a piece of example data might be '01/03/03')
But when I run a report over multiple months (ie, everything from %/01/03 or %/02/03) it does not sort the dates correctly, because (understandly) the database thinks it is sorting strings, not dates. So I get 01/01/03, 01/02/03, 02/01/03, 02/02/03, etc...
So, I think I need to convert the char field into a date, for the purposes of this report.
However, I'm finding that:
SELECT CONVERT(DATETIME, '01/03/03') returns 2003-01-03 00:00:00.000, which the system reads as the 3rd Jan 2003, instead of 1st March 2003.
and if I try to use a 'style' (ie, 103 which is British/French) then I get the following:
SELECT CONVERT(DATETIME, '01/03/03', 103) = Syntax error converting datetime from character string.
Can anyone help? Am I even going about this the right way??
Thanks in advance!
Annelies