Unix Technical Forum

leading zeroes in day, month

This is a discussion on leading zeroes in day, month within the Informix forums, part of the Database Server Software category; --> Hello! I would like to show day(date) and month(date) with leading zeroes. Is it any way to do that ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 08:17 PM
Mitja Udovc
 
Posts: n/a
Default leading zeroes in day, month

Hello!

I would like to show day(date) and month(date) with leading zeroes. Is it
any way to do that

Mitja


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 08:17 PM
Gorazd Hribar Rajterič
 
Posts: n/a
Default Re: leading zeroes in day, month

In 4GL write:
....
DEFINE
aDay SMALLINT,
aMonth SMALLINT
....
LET aDay = DAY(TODAY)
LET aMonth = MONTH(TODAY)
DISPLAY aDay using "&&"
DISPLAY aMonth USING "&&"
....

Gorazd

"Mitja Udovc" <mitja.udovc@mf.uni-lj.si> wrote in message
news:bo5jg2$llg$1@planja.arnes.si...
> Hello!
>
> I would like to show day(date) and month(date) with leading zeroes. Is it
> any way to do that
>
> Mitja
>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 08:17 PM
Jonathan Leffler
 
Posts: n/a
Default Re: leading zeroes in day, month

Mitja Udovc wrote:
> I would like to show day(date) and month(date) with leading zeroes. Is it
> any way to do that


Lots - but which language are you using? DB-Access, ESQL/C, I4GL,
something else? What I18N/L10N issues do you have to deal with -
which sequence of fields do you use in a date string?

You can probably use a CASE expression to fix it up. Alternatively,
you could substring a string representation of the date value.

Why does it matter?

--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 08:17 PM
Mitja Udovc
 
Posts: n/a
Default Re: leading zeroes in day, month

I'm using dbacess and i tried with substring but it doesn't work

like

SELECT (DAY(test.date)+100)[2,3]



"Jonathan Leffler" <jleffler@earthlink.net> wrote in message
news:4rtpb.4940$qh2.4352@newsread4.news.pas.earthl ink.net...
> Mitja Udovc wrote:
> > I would like to show day(date) and month(date) with leading zeroes. Is

it
> > any way to do that

>
> Lots - but which language are you using? DB-Access, ESQL/C, I4GL,
> something else? What I18N/L10N issues do you have to deal with -
> which sequence of fields do you use in a date string?
>
> You can probably use a CASE expression to fix it up. Alternatively,
> you could substring a string representation of the date value.
>
> Why does it matter?
>
> --
> Jonathan Leffler #include <disclaimer.h>
> Email: jleffler@earthlink.net, jleffler@us.ibm.com
> Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-19-2008, 08:17 PM
John Carlson
 
Posts: n/a
Default Re: leading zeroes in day, month

On Mon, 3 Nov 2003 15:32:04 +0100, "Mitja Udovc"
<mitja.udovc@mf.uni-lj.si> wrote:

>I'm using dbacess and i tried with substring but it doesn't work
>
>like
>
>SELECT (DAY(test.date)+100)[2,3]
>
>
>



What about using the lpad function, like....
select lpad(month(whatever_date), 2, "0"), lpad(day(whatever_date), 2,
"0")
from whatever_table


Not too sure which version you have, but this works in 9.21 and 9.30.
Possibly 7.31 too???


>"Jonathan Leffler" <jleffler@earthlink.net> wrote in message
>news:4rtpb.4940$qh2.4352@newsread4.news.pas.earth link.net...
>> Mitja Udovc wrote:
>> > I would like to show day(date) and month(date) with leading zeroes. Is

>it
>> > any way to do that

>>
>> Lots - but which language are you using? DB-Access, ESQL/C, I4GL,
>> something else? What I18N/L10N issues do you have to deal with -
>> which sequence of fields do you use in a date string?
>>
>> You can probably use a CASE expression to fix it up. Alternatively,
>> you could substring a string representation of the date value.
>>
>> Why does it matter?
>>
>> --
>> Jonathan Leffler #include <disclaimer.h>
>> Email: jleffler@earthlink.net, jleffler@us.ibm.com
>> Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/
>>

>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-19-2008, 08:17 PM
Mitja Udovc
 
Posts: n/a
Default Re: leading zeroes in day, month

lpad doesnt work

Mitja

"John Carlson" <john_carlson@whsmithusa.com> wrote in message
news:4mrcqvg10v25e7qoguqnv5ouscnsem4old@4ax.com...
> On Mon, 3 Nov 2003 15:32:04 +0100, "Mitja Udovc"
> <mitja.udovc@mf.uni-lj.si> wrote:
>
> >I'm using dbacess and i tried with substring but it doesn't work
> >
> >like
> >
> >SELECT (DAY(test.date)+100)[2,3]
> >
> >
> >

>
>
> What about using the lpad function, like....
> select lpad(month(whatever_date), 2, "0"), lpad(day(whatever_date), 2,
> "0")
> from whatever_table
>
>
> Not too sure which version you have, but this works in 9.21 and 9.30.
> Possibly 7.31 too???
>
>
> >"Jonathan Leffler" <jleffler@earthlink.net> wrote in message
> >news:4rtpb.4940$qh2.4352@newsread4.news.pas.earth link.net...
> >> Mitja Udovc wrote:
> >> > I would like to show day(date) and month(date) with leading zeroes.

Is
> >it
> >> > any way to do that
> >>
> >> Lots - but which language are you using? DB-Access, ESQL/C, I4GL,
> >> something else? What I18N/L10N issues do you have to deal with -
> >> which sequence of fields do you use in a date string?
> >>
> >> You can probably use a CASE expression to fix it up. Alternatively,
> >> you could substring a string representation of the date value.
> >>
> >> Why does it matter?
> >>
> >> --
> >> Jonathan Leffler #include <disclaimer.h>
> >> Email: jleffler@earthlink.net, jleffler@us.ibm.com
> >> Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/
> >>

> >

>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-19-2008, 08:17 PM
John Carlson
 
Posts: n/a
Default Re: leading zeroes in day, month

On Mon, 3 Nov 2003 16:37:11 +0100, "Mitja Udovc"
<mitja.udovc@mf.uni-lj.si> wrote:

What version of the engine are you running??

>lpad doesnt work
>
>Mitja
>
>"John Carlson" <john_carlson@whsmithusa.com> wrote in message
>news:4mrcqvg10v25e7qoguqnv5ouscnsem4old@4ax.com.. .
>> On Mon, 3 Nov 2003 15:32:04 +0100, "Mitja Udovc"
>> <mitja.udovc@mf.uni-lj.si> wrote:
>>
>> >I'm using dbacess and i tried with substring but it doesn't work
>> >
>> >like
>> >
>> >SELECT (DAY(test.date)+100)[2,3]
>> >
>> >
>> >

>>
>>
>> What about using the lpad function, like....
>> select lpad(month(whatever_date), 2, "0"), lpad(day(whatever_date), 2,
>> "0")
>> from whatever_table
>>
>>
>> Not too sure which version you have, but this works in 9.21 and 9.30.
>> Possibly 7.31 too???
>>
>>
>> >"Jonathan Leffler" <jleffler@earthlink.net> wrote in message
>> >news:4rtpb.4940$qh2.4352@newsread4.news.pas.earth link.net...
>> >> Mitja Udovc wrote:
>> >> > I would like to show day(date) and month(date) with leading zeroes.

>Is
>> >it
>> >> > any way to do that
>> >>
>> >> Lots - but which language are you using? DB-Access, ESQL/C, I4GL,
>> >> something else? What I18N/L10N issues do you have to deal with -
>> >> which sequence of fields do you use in a date string?
>> >>
>> >> You can probably use a CASE expression to fix it up. Alternatively,
>> >> you could substring a string representation of the date value.
>> >>
>> >> Why does it matter?
>> >>
>> >> --
>> >> Jonathan Leffler #include <disclaimer.h>
>> >> Email: jleffler@earthlink.net, jleffler@us.ibm.com
>> >> Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/
>> >>
>> >

>>

>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-19-2008, 08:17 PM
Doug Lawry
 
Posts: n/a
Default Re: leading zeroes in day, month

You must be on version 7 if you don't have "lpad". Here is a workaround
tested on SE 7.23 (the oldest version I have available):

CREATE PROCEDURE zerofill_2(number CHAR(2)) RETURNING CHAR(2);

WHILE LENGTH(number) < 2
LET number = "0" || number;
END WHILE

RETURN number;

END PROCEDURE;

-- Test --

SELECT
zerofill_2(DAY(TODAY)),
zerofill_2(MONTH(TODAY)),
zerofill_2(YEAR(TODAY) - 2000)
FROM
systables
WHERE
tabname = "systables";

Regards,
Doug Lawry
www.douglawry.webhop.org


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-19-2008, 08:18 PM
Jonathan Leffler
 
Posts: n/a
Default Re: leading zeroes in day, month

Mitja Udovc wrote:
> I'm using dbacess and i tried with substring but it doesn't work
> like
>
> SELECT (DAY(test.date)+100)[2,3]


SELECT SUBSTR(DAY(test.date) + 100, 2, 2) ...

(IIRC, SUBSTR function takes a start position and a length, rather
than start and end positions.)

> "Jonathan Leffler" <jleffler@earthlink.net> wrote:
>>Mitja Udovc wrote:
>>
>>> I would like to show day(date) and month(date) with leading
>>> zeroes. Is it any way to do that

>>
>>Lots - but which language are you using? DB-Access, ESQL/C, I4GL,
>>something else? What I18N/L10N issues do you have to deal with -
>>which sequence of fields do you use in a date string?
>>
>>You can probably use a CASE expression to fix it up. Alternatively,
>>you could substring a string representation of the date value.


It would be helpful to know which version of the server you are using
too - it helps people know whether SUBSTR(), for example, is going to
work for you.


--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-19-2008, 08:18 PM
Richard Spitz
 
Posts: n/a
Default Re: leading zeroes in day, month

On Mon, 3 Nov 2003, Mitja Udovc wrote:

> I would like to show day(date) and month(date) with leading zeroes. Is it
> any way to do that


Depending on your version of the engine (should work from 7.3 onwards):

to_char(date, "%d") gives you the day,
to_char(date, "%m") gives you the month,

both with leading zeroes.

HTH, Richard



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:43 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com