user3681993
user3681993

Reputation:

How To get previous date when subtracted from current date with no. of days in php

I am using a search option for retrieving data from database. The search criteria is between two dates. The default 'to date' is current system date and is using date() function. I want to set default 'from date' by 30 days less than current date. For example my 'To date, is 22-12-2014 then 'From date' be 22-11-2014. How can it set in php?

Upvotes: 2

Views: 151

Answers (1)

Manish Jesani
Manish Jesani

Reputation: 1357

try this

$to_date = date('d-m-Y');
$from_date = date('d-m-Y',strtotime("-1 month")); // or -30 days

Upvotes: 4

Related Questions