SCook Posted January 4, 2008 Share Posted January 4, 2008 Hi all, It's possible to get the number of seconds since the unix epoch with gettimeodday(). Is it also possible to convert a date to tyhe number of seconds? like 1/4/2008 0:00 am and get the seconds? Quote Link to comment https://forums.phpfreaks.com/topic/84534-date-conversion-using-gettimeofday/ Share on other sites More sharing options...
GingerRobot Posted January 4, 2008 Share Posted January 4, 2008 Sure, use the strtotime() function: <?php echo strtotime("1/4/2008 00:00:00"); ?> Note, the strtotime function works with the American m/d/y format - not the uk d/m/y format. Don't know where you're from, so i don't know if that's an issue or not. Quote Link to comment https://forums.phpfreaks.com/topic/84534-date-conversion-using-gettimeofday/#findComment-430675 Share on other sites More sharing options...
kenrbnsn Posted January 4, 2008 Share Posted January 4, 2008 The gettimeofday() returns the number of seconds since the unix epoch as part of the returned array: <?php $tod = gettimeofday(); echo $tod['sec']; ?> Use the strtotime() function to get the number of seconds for an arbitrary date: <?php echo strtotime('1/4/2008 12:00 am'); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/84534-date-conversion-using-gettimeofday/#findComment-430677 Share on other sites More sharing options...
SCook Posted January 4, 2008 Author Share Posted January 4, 2008 I am in the US, and that worked great. I didn't even realize strtotime would do that. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/84534-date-conversion-using-gettimeofday/#findComment-430683 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.