469,275 Members | 1,794 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Find the end date for a month

code green
1,726 Expert 1GB
On the first of each month I need to create a report from the previous month covering 1-15 and 16-end of month.
I am using the following code which forms part of a mssql query and part of the filenames.[PHP]$month = date('Y-m',strtotime('-1 month'));
$starts = array($month.'-01',$month.'-16');
$ends = array($month.'-15',$month.'-31');[/PHP] This creates arrays such as
Expand|Select|Wrap|Line Numbers
  1. Array 0=>2007-09-01,1=>2007-09-16);
  2. Array 0=>2007-09-15,1=>2007-09-31). 
h:m:s are added inside the query. Unfortunately the query is failing in mssql if there is no 31st of the month. I don't know why.
What additional code do I need to always generate the the last day of the previous month,
ie 31 for Jan, 28 for Feb (poss leap year problem) 30 for Apr etc
Thanks
Oct 30 '07 #1
2 5112
code green
1,726 Expert 1GB
I suppose I could use a look-up table.
Oct 30 '07 #2
code green
1,726 Expert 1GB
Its OK I solved it.
Used the date() 't' parameter. [PHP]$month = date('Y-m',strtotime('-1 month'));
$starts = array($month.'-01',$month.'-16');
$ends = array($month.'-15',$month.'-'.date('t',strtotime('-1 month')));[/PHP]
Oct 30 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

20 posts views Thread by Laguna | last post: by
12 posts views Thread by Assimalyst | last post: by
3 posts views Thread by Bob Sanderson | last post: by
6 posts views Thread by =?Utf-8?B?UGF1bA==?= | last post: by
10 posts views Thread by ashore | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.