0

I have one issue with date function below i have put my all code. Please check. I have used jQuery calender in my joomla component

 echo $data['startpublish'];

    $data['startpublish'] = date('Y-m-d', strtotime($data['startpublish']));
    echo "?>>>>>>>>>>>".$data['startpublish'];

    exit;

I have store my date into mm-dd-yy format. When i store 01-02-2015 then it will store data in DB in (Y-m-d) format and when i store 01-28-2015 (28 Janvary) then it will convert into 1970-01-01.

Please let me know what the issue . I have added both screenshot as well.

issue SS : http://prntscr.com/812w0c

correct SS : http://prntscr.com/812xbj

Pritesh Mahajan
  • 4,974
  • 8
  • 39
  • 64

1 Answers1

1

This is a strtotime quirk to do with the text date representation and the American illogical way of saying/writing dates used in the conversion having either - or / or . seperators.

Quote from the PHP Manual, now why did I go there for information I wonder.

Note:

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

So to make an american date format 01-28-2015 store properly you have to convert it to have / seperators like so for example

$data['startpublish'] = str_replace('-','/', $data['startpublish']);

$data['startpublish'] = date('Y-m-d', strtotime($data['startpublish']));
echo "?>>>>>>>>>>>".$data['startpublish'];
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149