Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP timestamp - first day of the week

Need to find the timestamp for the first minute of the first day of the current week.

What is the best way to do this?

<?php

$ts = mktime(); // this is current timestamp

?>
like image 813
acoder Avatar asked Mar 23 '12 17:03

acoder


2 Answers

If Monday is your first day:

$ts = mktime(0, 0, 0, date("n"), date("j") - date("N") + 1);
like image 183
Tchoupi Avatar answered Sep 21 '22 01:09

Tchoupi


If you think Monday is the first day of the current week...

$ts = strtotime('Last Monday', time());

If you think Sunday is the first day of the current week...

$ts = strtotime('Last Sunday', time());
like image 35
Ryan Kempt Avatar answered Sep 21 '22 01:09

Ryan Kempt