Jump to content

help with time


kirkh34

Recommended Posts

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>";

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.