CodeIgniter Forums
Howto; Date of x-days ago - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Howto; Date of x-days ago (/showthread.php?tid=10459)



Howto; Date of x-days ago - El Forum - 07-31-2008

[eluser]freshface[/eluser]
Hey

I want the data of x dags ago (26 days).
How do I do this? pseudo: $currentdate = date("Y-m-d") - 26;

Any thoughts?

Thx


Howto; Date of x-days ago - El Forum - 07-31-2008

[eluser]Pascal Kriete[/eluser]
Two that immediately come to mind:
Code:
$option_one = strtotime("-26 days");
$option_two = time() - 60 * 60 * 24 * 26

That'll give you the timestamp, and then use another function (date()) to format it.


Howto; Date of x-days ago - El Forum - 07-31-2008

[eluser]mironcho[/eluser]
Hi,
one way to achieve this is by setting the second argument of the date() function, which must be some unix timestamp:
Code:
$olddate = time() - (26 * 86400);
$currentdate = date("Y-m-d", $olddate);


edit: Inparo was faster then me Smile


Howto; Date of x-days ago - El Forum - 07-31-2008

[eluser]freshface[/eluser]
Nive guys, thx.
Easier then I thought