CodeIgniter Forums
How to get first day of previous month - 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: How to get first day of previous month (/showthread.php?tid=32628)



How to get first day of previous month - El Forum - 07-29-2010

[eluser]zeedy2k[/eluser]
What im trying to do is list fields where last update was after 1st day of the previous month

EG
We are currently on 28 July so would need it to calculate which updates occurred AFTER 1st June.

Is there an easy way of doing this?

Cheers
Robert


How to get first day of previous month - El Forum - 07-29-2010

[eluser]Krzemo[/eluser]
Is it database query related question?


How to get first day of previous month - El Forum - 07-29-2010

[eluser]zeedy2k[/eluser]
Yeah... Basically the field in the database of the last ad is 'lastad' and it is the current timestamp using time() that the record was created.


How to get first day of previous month - El Forum - 07-29-2010

[eluser]n0xie[/eluser]
Calculate the timestamp of the 1st of the previous month and use a WHERE clause in your query?


How to get first day of previous month - El Forum - 07-29-2010

[eluser]zeedy2k[/eluser]
Yeah thats not a problem... but whats the easiest way to calculate the 1st of the previous month?


How to get first day of previous month - El Forum - 07-29-2010

[eluser]Krzemo[/eluser]
From top of my head...
Code:
SELECT DATE_ADD(LAST_DAY(DATE_SUB(CURDATE(), INTERVAL 2 MONTH)), INTERVAL 1 DAY)