Hi, Using PHP 4, if I have a date, what is a function I could use to
give me a date that represents the first day of that month? For
example, if my date were "3/19/2006 8:00", I would want my function to
return "3/1/2006 8:00". Similarly what function would I use to return
the last day of the month? In the above example, the output I would
want returned is "3/31/2006 8:00".
Thanks, - 4 48191
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 la***********@zipmail.com wrote: if my date were "3/19/2006 8:00", I would want my function to return "3/1/2006 8:00".
See date() and mktime().
- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_*************************@hotmail.com
Jabber:iv*********@jabber.org ; iv*********@kdetalk.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFEB4tZ3jcQ2mg3Pc8RApx8AJ41L8w5nYc4Ugm0cA95tD BiFNiDuwCcD4/E
36+mLMZpQckMv64n1ja7aaE=
=gKuM
-----END PGP SIGNATURE----- la***********@zipmail.com wrote: Hi, Using PHP 4, if I have a date, what is a function I could use to give me a date that represents the first day of that month? For example, if my date were "3/19/2006 8:00", I would want my function to return "3/1/2006 8:00". Similarly what function would I use to return the last day of the month? In the above example, the output I would want returned is "3/31/2006 8:00".
The first date of the month is trivial: replace the day number with 1.
The last day of the month is somewhat harder, because this varies with
months and leap years. However, you could use checkdate to figure out
what the last day of the month is:
function getlastdayofmonth($month, $year) {
for ($day = 28; $day < 32; $day++) {
if (!checkdate($month, $day, $year)) return $day-1;
}
}
Sjoerd said the following on 03/03/2006 10:58: la***********@zipmail.com wrote: Hi, Using PHP 4, if I have a date, what is a function I could use to give me a date that represents the first day of that month? For example, if my date were "3/19/2006 8:00", I would want my function to return "3/1/2006 8:00". Similarly what function would I use to return the last day of the month? In the above example, the output I would want returned is "3/31/2006 8:00".
The first date of the month is trivial: replace the day number with 1. The last day of the month is somewhat harder, because this varies with months and leap years. However, you could use checkdate to figure out what the last day of the month is:
function getlastdayofmonth($month, $year) { for ($day = 28; $day < 32; $day++) { if (!checkdate($month, $day, $year)) return $day-1; } }
Or more directly:
function getLastDayOfMonth($month, $year)
{
return idate('d', mktime(0, 0, 0, ($month + 1), 0, $year));
}
--
Oli
Sjoerd wrote: la***********@zipmail.com wrote:
Hi, Using PHP 4, if I have a date, what is a function I could use to give me a date that represents the first day of that month? For example, if my date were "3/19/2006 8:00", I would want my function to return "3/1/2006 8:00". Similarly what function would I use to return the last day of the month? In the above example, the output I would want returned is "3/31/2006 8:00".
The first date of the month is trivial: replace the day number with 1. The last day of the month is somewhat harder, because this varies with months and leap years. However, you could use checkdate to figure out what the last day of the month is:
function getlastdayofmonth($month, $year) { for ($day = 28; $day < 32; $day++) { if (!checkdate($month, $day, $year)) return $day-1; } }
Or, once you have the first of the month, add one month and subtract one
day.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
================== This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kate |
last post by:
Hi...
I have a foxpro program which is for producing excel reports back
ended to foxpro table(.dbf). Since the table is getting bigger and
bigger, it slows down my program. I need a program...
|
by: Vijay Balki |
last post by:
I need to view a discussion posted last month in this group. How do I see
it?
VJ
|
by: Anon |
last post by:
Hello All!
I have written a simple app that auto downloads a file from a secure
ftp, renames it, and moves it to a network location. Everything works
great except the renaming part. I parse out...
|
by: bdtmike |
last post by:
I'm using the GridView control and have the Mode of the Pager set to
"NumericFirstLast". However, when there are several pages to display,
the pager shows only page numbers--and no First/Last...
|
by: Tony Ciconte |
last post by:
Does anyone know of or have any VBA code or similar logic that can
help distinguish similar first/last name combinations? For example, we
would like to prompt the user of a possible match when any...
|
by: Janick Bernet |
last post by:
I just stumbled upon this olap function and wondered why the "NULLS
FIRST/LAST" clause is not possible in normal order by but only using
row_number() over(). Sure, I can do a
SELECT *,...
|
by: remya1000 |
last post by:
i'm using ASP with MSAccess as database.
i have two buttons and two textbox in my page.
when i press my first button (First month) i need to display the current month in one textbox and last one...
|
by: One |
last post by:
Hi group -
I want to do a SELECT based on a date range - but mySQL syntax expects
the month range to be two digits.
So I have converted the month to show the leading zero like this :
...
|
by: Coolboy55 |
last post by:
Hi everyone, I'm having some trouble with a query. I have a history table where one of the fields is a date stamp. My query takes a date from the user, and I want the query to return all records...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
| |