php - comparing string to time -
i trying total figures study sql. want happen if row newer lastly go sql adding date , time tagged on report:
e.g.
141480128217,wrong_performance,g3t3,19/01/2013 02:58pm 182483629803,wrong_performance,g3t3,19/01/2013 03:01pm 108484044725,wrong_performance,g3t1,19/01/2013 03:10pm
so if ran , lastly row added 1 @ 03:01pm total 'wrong_performance' 2 running 1 time again want 3 i'm doubling each update first 2 , sec 5 , if there no new row still 8 next update (5 + 3) , on. avoid want create sure date in study newer lastly update sql (i adding date each row , replacing date previous lastly 1 added date in sql) string doesn't compare correctly. how go doing this? have tried few different methods have gotten nowhere.
edit have tried following:
$newdate = date("d/m/y/ h:i:s", strtotime("19/01/2013 01:42pm"));
and got result:
01/01/70/ 12:00:00
i tried switching day , month so:
$newdate = date("d/m/y h:i:s", strtotime("01/19/2013 01:42pm"));
and got following:
19/01/13 01:42:00
so how work study is?!?
result
$date = str_replace("/", "-", "19/01/2013 01:42pm"); $newdate = date("d/m/y h:i:s", strtotime("$date")); echo $newdate;
returned right date format!
convert date yyyy-mm-dd format (include time if want), dates can sorted numerically. first (or last, depending on how sort it) record newest.
edit:
str_replace fixed problem because quote php.net:
"dates in m/d/y or d-m-y formats disambiguated looking @ separator between various components: if separator slash (/), american m/d/y assumed; whereas if separator dash (-) or dot (.), european d-m-y format assumed."
thus, making separator -, made php d-m-y date rather m/d/y date.
php sql
No comments:
Post a Comment