Page 1 of 1

strtotime problem!

Posted: Mon Feb 16, 2009 9:49 pm
by melchor_06
my strtotime works perfectly fine when a user inputs his birthday which has the day, the month and the year.
but when a user did not input his day, month and year of his birthday.
same if its incomplete or the user had only input just one data or two.
still in the database it will put a value of 0.
and when it's echoed, it will ouput 01 Jan 1970.

how can i solve this?
so that if a user did not input his birthday, the database will just be blank.
and also if the user only input the day, still it will it corretly ouput it.
same goes if only the month or the year nor if one of its data has no input,
still it would correctly ouput the two data correctly.

Code: Select all

 
$calendar = $data['day']."/".$data['month']."/".$data['year'];
$date      = explode("/",$calendar);
        
$birthday = strtotime($date[0] .$date[1] . $date[2]);
 
echo $birthday;
 
thanks guys...

Re: strtotime problem!

Posted: Tue Feb 17, 2009 3:16 am
by mattpointblank
You need to either stop the data reaching the database when it's inserted, or filter it when it comes out. Something like:

Code: Select all

 
if($_POST['day'] == 0) {
 // either don't display a date, or set it to null in the insert query
}
 
I don't really understand how you can display a date without all the parts...?

Re: strtotime problem!

Posted: Tue Feb 17, 2009 3:33 am
by melchor_06
sir mattpointblank, i tried your solution before but it never worked out.

some user just wants to give either the only the day, or the month or the year of their birthday
nor the combination of the said data mostly only the day and the month but not all...

but still i want to display it without making a function for a user to use if he wants to hide the day, the month, mostly the year
or either the combination of the two data.

so if he do not want to show any of the data of his birthday, he'll just not have to input any...

Re: strtotime problem!

Posted: Tue Feb 17, 2009 8:47 am
by Bill H
You are npot going to be able to do that using a "date" field or a timestamp. Those database items are designed to hold an entire date. A timestamp holds the number of seconds elapsed since Jan 1, 1970. If you want to allow entry of partial dates you will need three fields, one for eact part of the date and will need to store them separately.