Jump to content

date conver help


UnknownPlayer

Recommended Posts

I have another problem :S

I converted m.d.Y H:i:s, but when i try to convert d.m.Y H:i:s, i cant save in mysql i get echo for this date 01.01.1970 01:00:00.

Example:

$str = $_POST['date'];
$datum = strtotime(str_replace('.','/',$str));
...mysql save code...

.. this code works for this format m.d.Y H:i:s, but when i make a format to read from mysql like d.m.Y H:i:s, and then try to save with $datum = strtotime(str_replace('.','/',$str));, i get 01.01.1970 01:00:00.

Help pls

Link to comment
https://forums.phpfreaks.com/topic/207548-date-conver-help/#findComment-1087258
Share on other sites

That's because the strtotime() functions doesn't recognize d/m/Y as a valid date. You have to convert your input to a string that is recognized as a date/time string:

<?php
list($d,$m,$rest) = explode('.',$_POST['date']);
$datum = strtotime("$m/$d/$rest");
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/207548-date-conver-help/#findComment-1087300
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.