Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the date of last week's (tuesday or any other day) in php?

Tags:

date

php

I think its possible but i cant come up with the right algorithm for it.

What i wanted to do was:

If today is monday feb 2 2009, how would i know the date of last week's tuesday? Using that same code 2 days after, i would find the same date of last week's tuesday with the current date being wednesday, feb 4 2009.

like image 622
lock Avatar asked Feb 02 '09 08:02

lock


1 Answers

Most of these answers are either too much, or technically incorrect because "last Tuesday" doesn't necessarily mean the Tuesday from last week, it just means the previous Tuesday, which could be within the same week of "now".

The correct answer is:

strtotime('tuesday last week')
like image 58
smo0f Avatar answered Oct 14 '22 12:10

smo0f