chaking Posted December 11, 2009 Share Posted December 11, 2009 So after thinking everything was working perfectly, I just noticed that a script that uses the function `strtotime` to convert a string (m/d/Y g:i:s A) into a unix timestamp doesn't actually return the correct seconds... instead it just leaves it at the closest minute (m/d/Y g:i A). I need a way to grab a date formatted as m/d/Y g:i:s A and convert it to the exact unix timestamp. I believe using mktime could work, however I'm not sure how to break up the date so that I can put each individual piece where it's supposed to go in the mktime function: So based on the format `m/d/Y g:i:s A` it will need to end up as mktime(g, i, s, m, d, Y) It would be great to get some help on how to break up the string to fit it into the mktime, but there's also a pretty big issue and that's the `A` at the end. It's AM or PM, so any ideas on how to convert that correctly would be appreciated too... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/184824-explode-a-date-and-convert-to-timestamp/ Share on other sites More sharing options...
chaking Posted December 11, 2009 Author Share Posted December 11, 2009 Ok, so thinking about it I guess I could add +12 to the `i` if the `A=='PM'`, I'm still struggling on how to explode that date into pieces though Quote Link to comment https://forums.phpfreaks.com/topic/184824-explode-a-date-and-convert-to-timestamp/#findComment-975703 Share on other sites More sharing options...
chaking Posted December 12, 2009 Author Share Posted December 12, 2009 The answer is in the sql statement... so instead of grabbing the string from the datetime field, it can be converted to unix timestamp before outputting the data as so: SELECT stamp = DATEDIFF(s, '19700101', some_column) FROM EVENTS WHERE some_column > 'xxx' And that solves that - w00t Quote Link to comment https://forums.phpfreaks.com/topic/184824-explode-a-date-and-convert-to-timestamp/#findComment-975745 Share on other sites More sharing options...
.josh Posted December 12, 2009 Share Posted December 12, 2009 <3 Quote Link to comment https://forums.phpfreaks.com/topic/184824-explode-a-date-and-convert-to-timestamp/#findComment-975757 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.