kirkh34 Posted April 26, 2010 Share Posted April 26, 2010 im trying to display the current time if it's the same day but if it's not the same day then just the day... i dont know how to match what mysql has to the current time because the current time from the function is from seconds from 1970 (i think thats what it is i forget) code: echo "<td>"; if (strftime('%a, %b %d, %Y', time()) == strftime('%a, %b %d, %Y', strtotime($message_date)) ) { print strftime('I:%M %p', strtotime($message_date)); } else { print strftime('%a, %b %d, %Y', strtotime($message_date)); } echo "</td>"; Quote Link to comment Share on other sites More sharing options...
ChemicalBliss Posted April 26, 2010 Share Posted April 26, 2010 Well if you just want it on the actual same day, you can just use date() and see if the day is the same; echo "<td>"; if (date("d", time()) == date("d", strtotime($message_date)) ) { print strftime('I:%M %p', strtotime($message_date)); } else { print strftime('%a, %b %d, %Y', strtotime($message_date)); } echo "</td>"; -cb- Quote Link to comment Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 Easiest way is to format a date using strftime for the mysql time stamp, and one for the current time. %F in strftime will give you the date as YYYY-MM-DD if(strftime('%F', strtotime($message_date)) == strftime('%F')) { } else { } strftime if not given a second parameter will use the current time. And strtotime creates a unix timestamp (second from 1970). So these will both output their dates Just a note, ChemicalBliss' code will only check the day of the month, not year or month. Quote Link to comment Share on other sites More sharing options...
kirkh34 Posted April 26, 2010 Author Share Posted April 26, 2010 ahh i see, thanks a lot guys, i should've researched the meanings of all the symbols for outputting time on php.net lol Quote Link to comment Share on other sites More sharing options...
kirkh34 Posted April 26, 2010 Author Share Posted April 26, 2010 well i can't seem to get it right here, it sounded like it was gonna work aright but... if i try to print strftime('%F'); to see what it says.. nothing shows up, so i thought that wasn't gonna work so i tried to do date('d,n,y', time() to match up which seems like the same thing but it doesn't work either, it just shows the month day and year, and it should just show the time since it's the same day, if i change the == to != to reverse it, it shows just the time but it's totally wrong, it's like 4 hours off, im pretty confused lol Quote Link to comment Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 If you use '%Y-%m-%d' instead of '%F' does anything output? I think not all operating systems support ALL of the codes for strftime. Quote Link to comment Share on other sites More sharing options...
kirkh34 Posted April 26, 2010 Author Share Posted April 26, 2010 yeah that worked but it does the same thing as date('d,n,y', time()), it shows the time but it's showing like 1:20pm instead of 10:20pm but i forgot to mention, the formula isn't working right, i have it so if today is equal to the date of the message, then it will output just the time, if it isn't equal to today it will just output the month day and year but it's backwards, it won't if i change it to != then it does output just the time like i want but it's hours off, confusing Quote Link to comment Share on other sites More sharing options...
ChemicalBliss Posted April 26, 2010 Share Posted April 26, 2010 echo "<td>"; if (date("d", time()) == date("d", strtotime($message_date)) ) { print date('h:i:s', strtotime($message_date)); } else { print date('d/m/y', strtotime($message_date)); } echo "</td>"; -cb- Quote Link to comment Share on other sites More sharing options...
kirkh34 Posted April 26, 2010 Author Share Posted April 26, 2010 awesome! thanks a lot, the times are correct, the were correct in the database the whole time but the other way showed the time hours off...i wonder why..oh well this works great thanks again 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.