Date YYYY-MM-DD

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hmvrulz
Forum Newbie
Posts: 20
Joined: Fri Oct 03, 2008 10:20 pm

Date YYYY-MM-DD

Post by hmvrulz »

I created a forum for entering birthday using php. So i get day n month as

1,2,3,4,.... and not with the leading 'ZERO'

Am storing the DATE as YYYY-MM-DD
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Date YYYY-MM-DD

Post by aceconcepts »

What's your question?
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Date YYYY-MM-DD

Post by papa »

Thanks for telling us!
hmvrulz
Forum Newbie
Posts: 20
Joined: Fri Oct 03, 2008 10:20 pm

Re: Date YYYY-MM-DD

Post by hmvrulz »

for selecting date i use drop down menus.. for creating that i use php... so the value of March wil be 3 and not 03...
so how do i convert it to 03 n then deliver it to the DB
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Date YYYY-MM-DD

Post by aceconcepts »

Check out the PHP manual. Type "PHP date" into Google.
hmvrulz
Forum Newbie
Posts: 20
Joined: Fri Oct 03, 2008 10:20 pm

Re: Date YYYY-MM-DD

Post by hmvrulz »

Code: Select all

 
<?php
 
  $isodate = sprintf("%04d-%02d-%02d", $year, $month, $day);
 
?>
 
 
tht works
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Date YYYY-MM-DD

Post by aceconcepts »

I was thinking of something more along the lines of:

Code: Select all

 
$date_for_db=date("Y-m-d", strtotime($your_date));
 
//$date_for_db should output as "YYYY-MM-DD"
 
Post Reply