0

How I can get current date and 15 days back date from current date in 'Y-m-d' format ??

e.g. if current date is 2011-06-21 then $currentdate=2011-06-21 and $dateback=2011-06-06;

3
Contributors
7
Replies
11
Views
6 Years
Discussion Span
Last Post by twiss
0
time()
date_create('15 days ago')

I need complete code that store currentdate as well as backdate..

1

Well, I suggest you learn PHP first? Storing values in a variable is quite well documented :)

$now = time();
$fifteendaysago = date_create('15 days ago');
Votes + Comments
date_create new for me - thanks :)
0

Well, I suggest you learn PHP first? Storing values in a variable is quite well documented :)

$now = time();
$fifteendaysago = date_create('15 days ago');

showing following error :

Catchable fatal error: Object of class DateTime could not be converted to string in C:\xampp\htdocs\3g\b.php on line 5
0

That's only if you echo it. Use $fifteendaysago->format(DATE_RFC3339) or something like that.

Edited by twiss: n/a

1

@A

Did you check the php.net manual for date_create()? If you'd bothered, you'd have seem that your can't print it out directly.

echo date_format($fifteendaysago, 'Y-m-d');

Also you must be using 5.2+

BTW - cheers twiss, always nice to learn new things. Must have missed that one.

Edited by diafol: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.