Day with leading 0

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Day with leading 0

Post by spacebiscuit »

Hi,

I am using the day() function to select the day of the week, is it possible to format the day so that it has a leading zero for days 1-9?

Thnaks in advance,

Rob.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

Thanks for the reply, I am not sure that will work in my case, here is the syntax i am using:

Code: Select all

select *, day(period_start_date) d1, left(month(period_start_date)....
Can it be done?

Thanks,

Rob.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

In SQL? No. It returns a number, not a string. Try just getting the whole period_start_date and formatting it with PHP's date() function.[/syntax]
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Post Reply