Alaa Abdelhaq Blog
You are having hard time with mysql datetime format? I wont blame you
I hope this short example will help you.
let say in your mysql database you are saving time on the datetime format
like this “2009-01-20 02:11:05″.
you need to pull it and add some days or time intervals and print it in a different format, thats easy do the following
1- In your query pulling the time, pull it this way:
UNIX_TIMESTAMP(time) AS time
this will covert it into unix timestamp, which will make it easier for you to manipulate it with php functions.
2- Add your time interval, let say we need to add 15 days.
$unix_timestamp_from_database = 1232410265; $time_from_db = $unix_timestamp_from_database; $new_time = $time_from_db + (15 * 86400);
86400seconds equals one day.
In unix timestamp we manipulate time by seconds.
so if you want to add an hour you add it like by (60 * 60)
which equals 3600 seconds.
3- Then you format it as you desire:
$new_time_format = date("d-M-Y", $new_time); echo $new_time_format;
hope it will help you
At first I should define, what is mod_rewrite?
mod_rewrite is a part of Apache server that can rewrite requested urls on the fly.
To enable mod_rewrite in Ubuntu, you just need to write this command in terminal
sudo a2enmod rewrite