PHP strtotime() with date() issue with year field

Aksh

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.

krishna

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="";
}

Demo

NOTE: $rec['birthday'] should be in format DD/MM or DD/MM/YY

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PHP date returning blank for Year "2090" with strtotime

From Dev

PHP date format and strtotime

From Dev

strtotime to time issue with a specific date

From Dev

strtotime to time issue with a specific date

From Dev

PHP date conversion using strtotime

From Dev

Formatting date using PHP strtotime

From Dev

Check a date interval with strtotime in php

From Dev

PHP strtotime Function: first day of this year

From Dev

PHP strtotime Function: first day of this year

From Dev

How to compare only year and month in date field in php mysql

From Dev

PHP strtotime timezone issue with '0:00 GMT'

From Dev

PHP strtotime issue when executing 2 days

From Dev

format of date string for strtotime() function in php

From Dev

String date to time in PHP - strtotime "loses hours"

From Dev

PHP date & strtotime adding 12 minutes?

From Dev

PHP Converting Integer to Date, reverse of strtotime

From Dev

PHP: Add some milliseconds to a date() with strtotime()

From Dev

PHP strtotime() "noon" must go before date

From Dev

strtotime is not working proper in php for future date?

From Dev

Php: Change language in date/strftime/strtotime

From Dev

PHP: strtotime revered return strange date?

From Dev

PHP: Add some milliseconds to a date() with strtotime()

From Dev

strtotime is not working proper in php for future date?

From Dev

format of date string for strtotime() function in php

From Dev

Issue with date field in textbox

From Dev

How to find last day of specific month of specific year with strtotime() in php

From Dev

PHP date actual year

From Dev

PHP date year format

From Dev

Displaying queried date field issue using PHP, CodeIgniter, and MySQL?

Related Related

HotTag

Archive