lxndr Posted January 28, 2008 Share Posted January 28, 2008 Was just wondering if there's an easy way of being able to display a unix timestamp for GMT so that if the date in question is today or yesterday the date gets displayed using those terms while all other dates get shown as actual dates. As an example, that would mean I'd get something like: user joined Person A Today, 02:52 AM Person B Yesterday, 06:59 PM Person C 25 Jan 2008, 04:45 PM Person D 24 Jan 2008, 11:02 AM Person E 24 Jan 2008, 09:34 AM TIA for any help or advice. Quote Link to comment https://forums.phpfreaks.com/topic/88223-solved-date-display-using-today-yesterday/ Share on other sites More sharing options...
Jackanape Posted January 28, 2008 Share Posted January 28, 2008 How about just a simple "IF" loop to see if the timestamp is the same as today's, using the date() function? Or, am I misunderstanding your need? Quote Link to comment https://forums.phpfreaks.com/topic/88223-solved-date-display-using-today-yesterday/#findComment-451446 Share on other sites More sharing options...
lxndr Posted January 28, 2008 Author Share Posted January 28, 2008 How about just a simple "IF" loop to see if the timestamp is the same as today's, using the date() function? Or, am I misunderstanding your need? detecting "yesterday" isn't as simple as it appears unless I'm missing something ? Quote Link to comment https://forums.phpfreaks.com/topic/88223-solved-date-display-using-today-yesterday/#findComment-451471 Share on other sites More sharing options...
Jackanape Posted January 28, 2008 Share Posted January 28, 2008 I'm thinking something as simple as: if (date('m/d/y', $timestamp) = date('m/d/y', strtotime('-1 day')) { $listed_day = 'Yesterday' } else { $listed_day = date('m/d/y') } I used a different format, now that I look at your original post again, but the concept remains. strtotime() should solve your problem. Quote Link to comment https://forums.phpfreaks.com/topic/88223-solved-date-display-using-today-yesterday/#findComment-451529 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.