Skip to content
Advertisement

PHP Date Function Seven days previous

I am trying to use PHP’s Date Function to get the date of 7 days earlier in YYYY-MM-DD format.

date('Y-m-d');

when i try

date('Y-m-d-7');

i get an error

Advertisement

Answer

Use the strtotime method provided by PHP.

date('Y-m-d', strtotime('-7 days'))

Thanks to @lonesomeday for pointing out my mistake in the comments 😉

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement