Jump to content

Date from db


ziggy_909

Recommended Posts

Do you mean, every 1st date of the month?

OR please explain more clearly.

 

for the returned date from the db .. i need to display it in a table as the 01-previous month- same year

 

eg returned date 2009-12-24 is displayed as 2009-11-01

    returned date 2010-06-02 is displayed as 2010-05-01

 

Link to comment
https://forums.phpfreaks.com/topic/223204-date-from-db/#findComment-1153887
Share on other sites

Try the link fortnox007 posted above, its a rich source of date functions.

If still can't figure it out, post the code u tried.

 

DATE_SUB(tbl_col, INTERVAL 1 MONTH),

 

this will remove 1 month from the date...

 

date_sub(tbl_co, interval day(tbl_col)-1 day)

 

this will display date as 1st day of the month

 

is there a way to combine both?

Link to comment
https://forums.phpfreaks.com/topic/223204-date-from-db/#findComment-1153919
Share on other sites

This should get you started.

SELECT DATE_FORMAT(DATE_SUB(tbl_col, INTERVAL 1 MONTH), '%Y-%m-01') FROM table

 

thanks that worked a treat... another quick question?

 

is there a way to return the first working day of the month ie if the 01st is a sunday return 02nd instead

 

 

Link to comment
https://forums.phpfreaks.com/topic/223204-date-from-db/#findComment-1153926
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.