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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.