phppaper Posted April 18, 2011 Share Posted April 18, 2011 Dear all, how can I convert a string "yyyy-mm-dd hh:mm" into a really datetime value with php? thanks! Link to comment https://forums.phpfreaks.com/topic/234026-convert-datetime-string-into-datetime/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 18, 2011 Share Posted April 18, 2011 Define: really datetime value? I can think of at least three different things that could mean. Link to comment https://forums.phpfreaks.com/topic/234026-convert-datetime-string-into-datetime/#findComment-1202849 Share on other sites More sharing options...
phppaper Posted April 18, 2011 Author Share Posted April 18, 2011 datetime is any "yyyy-mm-dd hh:mm" which can be compare rather than a solid string which cannot be compared. Thanks! Link to comment https://forums.phpfreaks.com/topic/234026-convert-datetime-string-into-datetime/#findComment-1202850 Share on other sites More sharing options...
PFMaBiSmAd Posted April 18, 2011 Share Posted April 18, 2011 If you have two strings in the format: "yyyy-mm-dd hh:mm" (with leading zeros so that each field will always be the same length that you have shown in that format), you can directly perform greater-than, less-then, and equal comparisons between those strings. Link to comment https://forums.phpfreaks.com/topic/234026-convert-datetime-string-into-datetime/#findComment-1202853 Share on other sites More sharing options...
phppaper Posted April 18, 2011 Author Share Posted April 18, 2011 Thanks, but from what you are saying is that we compare the 2 values within the MYSQL. What I want is just compare within PHP code. Any thoughts? like: if( > ) { } Link to comment https://forums.phpfreaks.com/topic/234026-convert-datetime-string-into-datetime/#findComment-1202857 Share on other sites More sharing options...
PFMaBiSmAd Posted April 18, 2011 Share Posted April 18, 2011 mysql has nothing to do with the reply above. Do you actually have a question or problem that you are trying to solve? Link to comment https://forums.phpfreaks.com/topic/234026-convert-datetime-string-into-datetime/#findComment-1202860 Share on other sites More sharing options...
phppaper Posted April 18, 2011 Author Share Posted April 18, 2011 Let me get this right, so what you are saying is: $dateone = 2011-04-01 09:11 $datetwo = 2011-04-02 09:11 they can be compared? without convert to date? $datetwo > $dateone = true right? Link to comment https://forums.phpfreaks.com/topic/234026-convert-datetime-string-into-datetime/#findComment-1202862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.