I have a problem when i am converting a String Date datatype into a date time format. I am using this code
$birthday = date('Y-m-d', strtotime($rec['birthday']));
The problem is that when only 'Date-Month' fields are coming then it will generate by default '1970'.But i want to save this as 'Date-Month-0000'.how can we solve this problelm.
try this.
$rec['birthday']= "03/11/2011";
if(isset($rec['birthday']) && $rec['birthday'] != "")
{
$dates = explode("/",$rec['birthday']);
if(!isset($dates[2]))
$dates[2] = "0000";
$newdate = $dates[0]."-".$dates[1]."-".$dates[2];
echo $newdate;
}
else
{
$newdate="";
}
NOTE: $rec['birthday']
should be in format DD/MM
or DD/MM/YY
try This: Date Format(dd/mm/yyyy)
$date = explode('/', $rec['birthday']);
if(sizeof($date) == 2)
{
$new_date = $date[0].'/'.$date[1].'/'.'0000';
}
else
{
$new_date = $rec['birthday'];
}
Try this -
$date = explode('/', $rec['birthday']);
if(!isset($date[2])){
$new_date = $date[0].'-'.$date[1].'-'.'0000';
}
else{
$new_date = $date[0].'-'.$date[1].'-'.$date[2];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.