retrieve current date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chxxangie
Forum Newbie
Posts: 12
Joined: Wed Sep 19, 2007 10:00 pm

retrieve current date

Post by chxxangie »

Code: Select all

 
$current_date   = date('Y-m-d');
$current_time   = date('G:i:s');
$current_time   = date('G:i:s', strtotime("+8 hours", strtotime($current_time))); 
 
now i can retrieve the current time. but how to retrieve the current date...?
thanks in advance...
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: retrieve current date

Post by mattpointblank »

The first line of that code should give the current date...?
chxxangie
Forum Newbie
Posts: 12
Joined: Wed Sep 19, 2007 10:00 pm

Re: retrieve current date

Post by chxxangie »

ok... like now in my country, the date is 2009-01-10.
but when i echo the first line, the date is 2009-01-09.
so how to make it when the time + 8 hours, the date will be auto adjusted to 2009-01-10...?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: retrieve current date

Post by John Cartwright »

Take a look at date_default_timezone_set for adjusting your timezone.
chxxangie
Forum Newbie
Posts: 12
Joined: Wed Sep 19, 2007 10:00 pm

Re: retrieve current date

Post by chxxangie »

Jcart wrote:Take a look at date_default_timezone_set for adjusting your timezone.
it is works... thanks for helping....
this method is easier to echo the date and time... i even don't need to add 8 hours for the time.....
Post Reply