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? Quote Link to comment 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. Quote Link to comment 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 ? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
UnknownPlayer Posted July 14, 2010 Author Share Posted July 14, 2010 Thanks xD Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
UnknownPlayer Posted July 17, 2010 Author Share Posted July 17, 2010 Thanks, it works xD Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.