473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 5301
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

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

Similar topics

6
by: N8tor | last post by:
I'm a programming neophyte so needless to say I need some help on some VB scripting. I need to create some code to find what month it will be this coming Saturday. I also need to do the same...
20
by: Laguna | last post by:
Hi Gurus, I want to find the expiration date of stock options (3rd Friday of the month) for an any give month and year. I have tried a few tricks with the functions provided by the built-in...
13
by: Sue | last post by:
I'm working on a database that keeps track of employees hired by a general contractor on a project by project basis. These employees are hired to work on a project and are then laid off either at...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
23
by: thebjorn | last post by:
For the purpose of finding someone's age I was looking for a way to find how the difference in years between two dates, so I could do something like: age = (date.today() - born).year but that...
3
by: Bob Sanderson | last post by:
I have a PHP web page which uses a HTML form. I would like to enter dates into the date fields using a JavaScript calendar, similar to the way phpMyAdmin does. Can anyone recommend a JavaScript...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
HI I have a stored procedure that returns data with a date field in the form of a DateTime type. I need to place data in variables based on days of the week starting with the first thursday of the...
5
by: cssExp | last post by:
the problem is, i have a dynamic database driven site, each data is entered with year, week etc.. 2 months ago assuming I'll create sort option in future i put everything, i.e year, week, hour,...
10
by: ashore | last post by:
Guys, the line below just returned "Dec 07" as the date for one month back from today. Hardly life-threatening, but any thoughts? <?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),...
2
by: mshroom12 | last post by:
I am having trouble with the following project on hand. I use Eclipse to do my work in Java. This is what I'm supposed to complete. Date Validation In this exercise you will write a program...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.