UnknownPlayer Posted July 12, 2010 Share Posted July 12, 2010 How can i convert from "m.d.Y H:i:s" to timestamp? Example: 1278977150 = 07.13.2010 01:25:50 .. now how can i convert from 07.13.2010 01:25:50 to 1278977150, what is the function? Link to comment https://forums.phpfreaks.com/topic/207548-date-conver-help/ Share on other sites More sharing options...
Pikachu2000 Posted July 12, 2010 Share Posted July 12, 2010 If you replace the decimal points in the date with slashes, strtotime() will do it. Link to comment https://forums.phpfreaks.com/topic/207548-date-conver-help/#findComment-1085119 Share on other sites More sharing options...
UnknownPlayer Posted July 13, 2010 Author Share Posted July 13, 2010 Can u give me example, for this date: 07.13.2010 01:25:50 ? Link to comment https://forums.phpfreaks.com/topic/207548-date-conver-help/#findComment-1085247 Share on other sites More sharing options...
kenrbnsn Posted July 13, 2010 Share Posted July 13, 2010 <?php $str = '07.13.2010 01:25:50'; echo strtotime(str_replace('.','/',$str)); ?> Ken Link to comment https://forums.phpfreaks.com/topic/207548-date-conver-help/#findComment-1085264 Share on other sites More sharing options...
UnknownPlayer Posted July 14, 2010 Author Share Posted July 14, 2010 Thanks xD Link to comment https://forums.phpfreaks.com/topic/207548-date-conver-help/#findComment-1085752 Share on other sites More sharing options...
UnknownPlayer Posted July 16, 2010 Author Share Posted July 16, 2010 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 More sharing options...
kenrbnsn Posted July 17, 2010 Share Posted July 17, 2010 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 More sharing options...
UnknownPlayer Posted July 17, 2010 Author Share Posted July 17, 2010 Thanks, it works xD Link to comment https://forums.phpfreaks.com/topic/207548-date-conver-help/#findComment-1087432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.