Learn how to program OOP in PHP and convert MySQL timestamp to the “Ago” format. Using a PHP class. Get the Zip Download Package Here: …
Original source
Learn how to program OOP in PHP and convert MySQL timestamp to the “Ago” format. Using a PHP class. Get the Zip Download Package Here: …
Original source
26 responses to “PHP Convert MySQL Timestamp to Ago Format: OOP Class Tutorial Object Oriented Programming”
$periods=array("sec","min","hr","day","week","month","year","decade")
$lengths=array("60","60","24","7","4.35","12","10");
Here $periods.length = 8 and $lengths.length =7
then how can we compare it thats why I am receiving error when calculating sec and min ago. Adam ! Am I right . Please suggest me.
Thanks
Hey Adam It works for hr ,day,week,month,year but does not work for min and secs a lot of error and undesirable result please suggest.
why do you talk like that mfuker
can't work a lot of error, what will i do, wait for the answer
This worked amazing, Thank you very much!
But, Sir, had a small question. How can we put time as shown below, if more than a minute?
Example:
20 mins & 13 secs ago
– or –
20 days & 8 hours ago
This might really help in a long run when it comes to months and years. Because i suppose if a message or a user is 1 year & 11 months old it will still show "1 year ago".
Youre the best dude this is so much simpler than i thought
Thank alot, needed this for long time, God Memories
thanks you so much yeah !
…watched ALOT of your videos. Basically learned basic PHP from you. Congrats !! Pro teacher !!
People who are having
99999 ago or values in minus(), kindly set your timezone.Add these lines to your code
<?php
// Here Karachi is the name of city and Asia is the continent
date_default_timezone_set("Asia/Karachi");
?>
// for further details you can visit http://php.net/manual/en/timezones.php
Thank you.
Adam Khoury Rocks 😀
@Huda6000 you probably figured it by now, but for others! You put the php code before header tags and in the context of the page where ago should go, just echo the when variable between php brackets!
You code will look nasty if you have all words have s at the end, so in this case just use:
if($difference != 1 && (strpos($periods[$j],'s') == false)) $periods[$j].= "s";
Heloo Adam, your videos are amazing it help me a lot…this ago script works perfectly in my website.. but i need 'time left' code too… like 2 days ago – 2 month left.. i tried but fail.. i need help 🙁
This Video really works but i have a little challenge with the output. My time is starting from 4hrs ago, what is the problem with this? I used dynamic time generated from DATETIME in the DB
thanks alot, useful stuff
If you are using phpmyadmin,
1) You have to change your php.ini
date.timezone = 'put correct time zone here'
Example:
date.timezone = 'Asia/Ho Chi Minh'
you can find a list of supported time zones at:
us2.php.net/manual/en/timezones.php
2) You have to change the timezone in your mysql, this can be done a number of ways, google it and read
Example:
mysql_query("SET SESSION time_zone = 'enter timezone'");
OR
SET time_zone = 'enter timezone';
OR
date_default_timezone_set
this is really amazing ! thanks Adam !
@kwvideo please how did you fix the -13536 secs ago error….because i dont understand what you wrote as the answer..i really would like to know
that's my post he's reading out lol
i can't thank you enough!
Great tutorial 5/5 or 1thumb up LOL idk but i think another good tutorial would be how u made that very nice chatroom in flash i havent figured out how to make action script code to make an online user …thigy lol for lack of a better word
@flashbuilding Naw I don't think so at all. It would make my web apps cleaner and more powerful. I'd love to go a little further. You're awesome. Just thought you'd like to know I also got a call from a client on web intersect 😉
I only have one problem with your tuts, every time I watch them…I end up getting awesome sauce all over my screen !! You Rock Adam, Thanks for the great tut
Reaaly Coool 🙂
@ssuhotcoco25 – Not too dorky? lol we could go a lil further.
I like this. I want to learn more about OOP/DRY programming.
sweet dude just what i needed thanks alot bro have 5 * dude and a thumbs up lol