Subject | RE: [firebird-support] Formating date to yyyymmdd |
---|---|
Author | Svein Erling Tysvær |
Post date | 2009-06-12T08:57:21Z |
For doing things quick and dirty, I sometimes use something similar to
EXTRACT(YEAR FROM BirthDate) ||
Case
when EXTRACT(MONTH FROM BirthDate) < 10 then
'0' || EXTRACT(MONTH FROM BirthDate)
else EXTRACT(MONTH FROM BirthDate)
end ||
Case
when EXTRACT(DAY FROM BirthDate) < 10 then
'0' || EXTRACT(DAY FROM BirthDate)
else EXTRACT(DAY FROM BirthDate)
end
(and before protests appear that this is client formatting and not something to do on servers: In Norway, our national PIN has the format ddmmyynnnnn and when I have to convert from a date format to CHAR(11), I think it is a good idea to do the transformation on the server).
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of kokok_kokok
Sent: 12. juni 2009 10:36
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Formating date to yyyymmdd
Using Firebird 2.0, how can I format a date to yyyymmdd?
For example Jan 15 2009 -> 20090115
My first approach has been using EXTRACT(YEAR FROM BirthDate) || EXTRACT(MONTH FROM BirthDate) || EXTRACT(DAY FROM BirthDate)
but it does not work for me because I need to lead zeros and I cannot find how do it. Maybe there is a direct function.
Thanks
EXTRACT(YEAR FROM BirthDate) ||
Case
when EXTRACT(MONTH FROM BirthDate) < 10 then
'0' || EXTRACT(MONTH FROM BirthDate)
else EXTRACT(MONTH FROM BirthDate)
end ||
Case
when EXTRACT(DAY FROM BirthDate) < 10 then
'0' || EXTRACT(DAY FROM BirthDate)
else EXTRACT(DAY FROM BirthDate)
end
(and before protests appear that this is client formatting and not something to do on servers: In Norway, our national PIN has the format ddmmyynnnnn and when I have to convert from a date format to CHAR(11), I think it is a good idea to do the transformation on the server).
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of kokok_kokok
Sent: 12. juni 2009 10:36
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Formating date to yyyymmdd
Using Firebird 2.0, how can I format a date to yyyymmdd?
For example Jan 15 2009 -> 20090115
My first approach has been using EXTRACT(YEAR FROM BirthDate) || EXTRACT(MONTH FROM BirthDate) || EXTRACT(DAY FROM BirthDate)
but it does not work for me because I need to lead zeros and I cannot find how do it. Maybe there is a direct function.
Thanks