Hi,
Using PHP 4.4.4, I want to generate an array that contains strings
representing days from Jan. 1, 2005 to whatever the current day is.
So the array would contain the first values
'2005-01-01', '2005-01-02', '2005-01-03'
and end with the values
'2007-01-27', '2007-01-28'
In case you're interested, I will then take this array and populate a
MySQL table.
Thanks for any advice, - Dave 11 2464
Should do it. Uses unix time stamps.
<?php
function generate_dates($start, $end)
{
$start = strtotime($start);
$end = strtotime($end);
$oneday = 86400;
$return = array();
for ($current = $start; $current <= $end; $current+=$oneday)
{
$return[] = $current;
}
return $return;
}
print '<pre>'; print_r(generate_dates('jan 1, 2005','today'));
?>
Hi,
Using PHP 4.4.4, I want to generate an array that contains strings
representing days from Jan. 1, 2005 to whatever the current day is.
So the array would contain the first values
'2005-01-01', '2005-01-02', '2005-01-03'
and end with the values
'2007-01-27', '2007-01-28'
In case you're interested, I will then take this array and populate a
MySQL table.
Thanks for any advice, - Dave
--
Carl Vondrick www.CarlSoft.net la***********@zipmail.com wrote:
Using PHP 4.4.4, I want to generate an array that contains strings
representing days from Jan. 1, 2005 to whatever the current day is.
So the array would contain the first values
<?php
$D = array(); // For results
$f = 'Y-m-d'; // Desired date format
$d = 1104537600; // 1 Jan 2005, Unix timestamp
while ($d < time()) // While still in the past...
{
$D[] = date($f,$d); // Add this date to the list
$d += 24*60*60; // The next date is 24 hours later
}
print_r($D); // Let's see what we've got!
?>
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
Carl Vondrick wrote:
$oneday = 86400;
Watch out for daylight-saving time. There may be Days longer or shorter
than 24h! Never start at Midnight.
Or use mktime. mktime(0,0,0,2,0,2007) is Jan. 31. 2007 and
mktime(0,0,0,1,32,2007) is Feb. 1.
Heiko
-- http://portal.richler.de/ Namensportal zu Richler http://www.richler.de/ Heiko Richler: Computer - Know How! http://www.richler.info/ private Homepage
Heiko Richler wrote:
Watch out for daylight-saving time. There may be Days longer or shorter
than 24h! Never start at Midnight.
That's a good point. You can workaround it by using UTC though, as UTC
doesn't have daylight savings.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
On 29 Jan, 07:28, Heiko Richler <heiko-rich...@nefkom.netwrote:
Carl Vondrick wrote:
$oneday = 86400;Watch out for daylight-saving time. There may be Days longer or shorter
than 24h! Never start at Midnight.
Or use mktime. mktime(0,0,0,2,0,2007) is Jan. 31. 2007 and
mktime(0,0,0,1,32,2007) is Feb. 1.
Heiko
--http://portal.richler.de/Namensportal zu Richlerhttp://www.richler.de/ Heiko Richler: Computer - Know How!http://www.richler.info/ private Homepage
Yes, DST is a real gotcha. I had a similar problem which was discussed
in this forum a while ago.
I was advised to use strtotime. My query was regarding adding numbers
of weeks. In your case you'd use something like:
$adate = strtotime("+1 day", strtotime($adate));
Heiko Richler wrote:
Watch out for daylight-saving time. There may be Days longer or shorter
than 24h! Never start at Midnight.
Good point!
KRAMER: Look how dark it's gettin' already.
JERRY: Well, it's not Daylight Savings Time yet.
KRAMER: When does it start?
JERRY: I don't know, they just tell you the night before.
KRAMER: Uh. Well, I'm sick o' waiting. I am springin' ahead riiight now.
JERRY: Oh, I'm sure that won't cause any problems..
--
Carl Vondrick www.CarlSoft.net
On Jan 28, 9:39 pm, "laredotorn...@zipmail.com"
<laredotorn...@zipmail.comwrote:
Hi,
Using PHP 4.4.4, I want to generate an array that contains strings
representing days from Jan. 1, 2005 to whatever the current day is.
So the array would contain the first values
'2005-01-01', '2005-01-02', '2005-01-03'
and end with the values
'2007-01-27', '2007-01-28'
In case you're interested, I will then take this array and populate a
MySQL table.
Thanks for any advice, - Dave
I thought I'd see if I could figure it out my own version. This seems
to work:
function daysUntilNow($month, $day, $year, $format = 'Y-m-d') {
$d = array();
$ts = 0;
while ( ($ts = mktime(0,0,0,$month,$day,$year)) < time() ){
$ts = mktime(0,0,0,$month,$day,$year);
$d[] = date($format,$ts);
$day++; // increment days
}
return $d;
}
On Jan 29, 6:46 pm, "Curtis" <dye...@gmail.comwrote:
function daysUntilNow($month, $day, $year, $format = 'Y-m-d') {
$d = array();
$ts = 0;
while ( ($ts = mktime(0,0,0,$month,$day,$year)) < time() ){
$ts = mktime(0,0,0,$month,$day,$year);
$d[] = date($format,$ts);
$day++; // increment days
}
return $d;
}
Grr, Google Groups borked my code. Pretend there's a closing brace for
the function.
Curtis <dy****@gmail.comwrote:
On Jan 29, 6:46 pm, "Curtis" <dye...@gmail.comwrote:
>function daysUntilNow($month, $day, $year, $format = 'Y-m-d') { $d = array(); $ts = 0;
while ( ($ts = mktime(0,0,0,$month,$day,$year)) < time() ){ $ts = mktime(0,0,0,$month,$day,$year); $d[] = date($format,$ts); $day++; // increment days } return $d;
}
Grr, Google Groups borked my code. Pretend there's a closing brace for
the function.
There is in real newsreaders :P
--
Rik Wasmus
Rik wrote:
Curtis <dy****@gmail.comwrote:
>On Jan 29, 6:46 pm, "Curtis" <dye...@gmail.comwrote:
>>function daysUntilNow($month, $day, $year, $format = 'Y-m-d') { $d = array(); $ts = 0;
while ( ($ts = mktime(0,0,0,$month,$day,$year)) < time() ){ $ts = mktime(0,0,0,$month,$day,$year); $d[] = date($format,$ts); $day++; // increment days } return $d;
}
Grr, Google Groups borked my code. Pretend there's a closing brace for the function.
There is in real newsreaders :P
--Rik Wasmus
Yeah, I finally found out my ISP's news server. I'm using Thunderbird
as my news client, for the moment, but I still want to check out Opera.
I hope Thunderbird is breaking the lines after the right amount of
characters.
--
Curtis, free of Google Groups
Curtis wrote:
I hope Thunderbird is breaking the lines after the right amount of
characters.
Yep, and it seems to be using format=flowed too, which can be a bonus for
some people.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: GIMME |
last post by:
Background ...
I've created a web application that allows a user to create an
HTML application from IE.
The application itself creates an XML representation of a XHTML
form. The XHTML...
|
by: Henry |
last post by:
Dear all,
Is there any DB2 SQL statement that could generate rows of intermediate
dates by providing the start and end dates??
If 2006-1-1 and 2006-1-31 are provided to the SQL, the output...
|
by: pitfour.ferguson |
last post by:
My dbase has the start date and end date of each visit. How can I ask
Access to list the day of the week of the start (easy), end (easy) and,
more importantly, the dates of the visit itself - ie...
|
by: sreedivya |
last post by:
Hi,
I am using Crystal Reports with .NET 2.0 for generating reports in my project. My database is SQLSERVER 2000.
I want to display list of absentees between 2 given dates.
For this I have written...
|
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: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: 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...
|
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,...
| |