Selecting date in given format
Posted in 1999
Topics: General Discussion
Hello, I'm searching for a way to select a date field in some nice format. What is the equivalent of Oracle's select to_char(date_field, 'yyyy-mm-dd') from table that forces the output string have format 1999-03-10, instead of the default 99-03-10. I want to stay in pure SQL for this task. Any hint would be apprecited, -- ------------------------------------------------------------------------ Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/ make vmlinux.exe -- SGI Visual Workstation Howto ------------------------------------------------------------------------
> I'm searching for a way to select a date field in some nice format. > What is the equivalent of Oracle's > > select to_char(date_field, 'yyyy-mm-dd') from table > > that forces the output string have format 1999-03-10, instead of the > default 99-03-10. I want to stay in pure SQL for this task. > > Any hint would be apprecited, Thanks to all who replied. I'm using 7.20 so I cannot use the to_char function available since 7.30. So I solved this by global setting of the environment variable DBDATE to 'Y4MD-'. -- ------------------------------------------------------------------------ Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/ make vmlinux.exe -- SGI Visual Workstation Howto ------------------------------------------------------------------------
Huy, You could write a select statement (without changing the DBDATE variable) as follows : select year(date_field) || '-' || extend(date_field, month to month) || '-' || extend(date_field, day to day) from table Hope this solves your problem. Suhas Honza Pazdziora wrote in message ... >Hello, > >I'm searching for a way to select a date field in some nice format. >What is the equivalent of Oracle's > > select to_char(date_field, 'yyyy-mm-dd') from table > >that forces the output string have format 1999-03-10, instead of the >default 99-03-10. I want to stay in pure SQL for this task. > >Any hint would be apprecited, > >-- >------------------------------------------------------------------------ > Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/ > make vmlinux.exe -- SGI Visual Workstation Howto >------------------------------------------------------------------------