Rajeev vishva
Rajeev vishva

Reputation: 15

get time and date in php

i am using

date_default_timezone_set('Africa/Nairobi');
$date = date('Y-m-d H:i:s'); 

but its always returning date and time form my PC.

Ex.. today is - 15/07/2015

and i changed my PC date to 17/09/2016

so php Date also returning same date...(17/09/2016)

is there any why to get real time and date?

what i have tried 1. simple date function 2. set timezone 3. i have searched on google but no luck yet...

Upvotes: 0

Views: 565

Answers (2)

IAmNoob
IAmNoob

Reputation: 641

There is nothing wrong with your code

date_default_timezone_set('Africa/Nairobi');
$date = date('Y-m-d H:i:s'); 

but as @Rizier123 said that if you are using XAMPP or WAMP or any other local server it will show the system time only. I would like to suggest you that put your code to an online server or use some online php compiler, then it will surely gonna give you the expected output.

Upvotes: 0

lhoppe
lhoppe

Reputation: 623

It will always return your PC date as it well should. Date & time functions use the server's date and time. So if you're running a local server (WAMP, XAMP or whatever) your PC will be the server and therefore it's time will be used. Setting the timezone should change the time accordingly though.

Upvotes: 1

Related Questions