1

How can I change the date and time of the server using PHP scripts? I know it will work if you change the time in the CLI but is it possible to change programatically?

I have created a route to that will pass a date and time localhost/date/{date}/time/{time} to test if it will work when I will call the date() in my controller.

Does someone know any method that can solve my problem?

Thanks in advance!

al. zheic
  • 29
  • 6
  • 2
    Possible duplicate of [PHP Change Server Date & Time](http://stackoverflow.com/questions/20177595/php-change-server-date-time) –  Sep 23 '16 at 04:41
  • Also see: [Using exec in php for setting system clock](http://stackoverflow.com/questions/7958972/using-exec-in-php-for-setting-system-clock) –  Sep 23 '16 at 04:42
  • you want to permanently change server data? or you are having time zone problem? – Archish Sep 23 '16 at 04:48
  • this is most likely a real bad idea, a lot of things you probably haven't thought about expect the time to be correct and not change unexpectedly –  Sep 23 '16 at 05:11
  • The more you can find with [This](http://php.net/manual/en/function.date-default-timezone-set.php). – Virb Sep 23 '16 at 05:13
  • @nogad yes it is a bad idea, but I just want to change time so that I can check my API if it is working. I know it can be done by changing the time in the server manually but I want to try changing it using php scripts. – al. zheic Sep 23 '16 at 05:15

2 Answers2

-1

Do exec('time 12:38:00 PM') and exec('date 11/24/2013') if on Windows. Credit to Dan for this answer.

This question's also a possible duplicate of PHP Change Server Date & Time.

Community
  • 1
  • 1
brld
  • 188
  • 2
  • 16
  • It's your responsibility to put that you tried this in the question in that case and not to just downvote things. – brld Sep 23 '16 at 14:32
-1

If you can do it in command line.. then you can do it in PHP too...

All you have to do is use PHP's shell_exec() function.

Try it.

Emz
  • 502
  • 1
  • 3
  • 11