473,378 Members | 1,631 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,378 software developers and data experts.

looping until today

I want to loop through dates, stopping at the current date

I set the enddate like this
$enddate=date('Y-m-d');

which prints out as '2006-04-01'

$l['cc_startdate'] comes from a DB with the column in date format

but when i do
for ($dl=$l['cc_startdate'];$dl < $enddate;$dl++)
{
print $dl;
blah

}

it goes on until the day is 99 and then loops again.
so how do I tell it that $enddate is in the same date format asthe
start date

Apr 1 '06 #1
4 1214
To convert a string to a date, you can use strtotime() to make a timestamp.

So, for example:

echo date ('Y-m-d',strotime('8:30 PM'));

pauld wrote:
I want to loop through dates, stopping at the current date

I set the enddate like this
$enddate=date('Y-m-d');

which prints out as '2006-04-01'

$l['cc_startdate'] comes from a DB with the column in date format

but when i do
for ($dl=$l['cc_startdate'];$dl < $enddate;$dl++)
{
print $dl;
blah

}

it goes on until the day is 99 and then loops again.
so how do I tell it that $enddate is in the same date format asthe
start date


--
Carl Vondrick
Web-Engineer
www.carlsoft.net
Apr 1 '06 #2
Message-ID: <11**********************@z34g2000cwc.googlegroups .com> from
pauld contained the following:
it goes on until the day is 99 and then loops again.
so how do I tell it that $enddate is in the same date format asthe
start date


Use timestamps

$enddate=strtotime('now');

for ($dl=strtotime('2006-3-1');$dl < $enddate;$dl=$dl+24*60*60)
{
print date('Y-m-d',$dl)."<br>";

}
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Apr 1 '06 #3
i tried strtitme("now ") which prints 1143878058 but the loop still
goes round and round
with

$date=("Y-m-d");
$enddate=strtotime($date);

it prints -1 and no loop at all.

Apr 1 '06 #4
thank you . I also need to use the date format as a lookup in an sql
query

end result that works

$date=("now");
$enddate=strtotime($date);
//print he dates from start date to present
for ( $dl=strtotime($l['cc_startdate']) ;$dl < $enddate ;
$dl=$dl+24*60*60)
//for ($dl=$l['cc_startdate'];$dl < $enddate;$dl++)
{$dlookup=date('Y-m-d',$dl);
//////////////////cell for date
print '<tr><td>'.$dlookup.'</td>';
print '<td>';
{
$sql2='SELECT * FROM table WHERE date=\''.$dlookup.'\'';

etc

Apr 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Lyle Fairfield | last post by:
The stored procedure script below is an example of how looping, case statements and output parameters can be used in MS-SQL stored procedures to accomplish things for which we may have had to use...
5
by: Stimp | last post by:
This is a question I'm carrying over from a previous one I made today since I've simplified where the problem is... I have a datatable, tblFeatures, which has around 30 columns (one for each...
13
by: JayCallas | last post by:
I know this question has been asked. And the usual answer is don't use cursors or any other looping method. Instead, try to find a solution that uses set-based queries. But this brings up...
3
by: veg_all | last post by:
How do you replace an occurence until a certain point: You can see my example code below and the output: $string1 = 'Hello world today'; $string2 = 'Hello blahblah'; $string1 = preg_replace...
2
by: clinttoris | last post by:
Hello, If someone could help me it would be appreciated as I am not having much luck. I'm struggling with my asp code and have some questions relating to asp and oracle database. First...
22
Dököll
by: Dököll | last post by:
Hiya, Partners! I have been into it for 12 hours straight this week-end, my son is very unhappy. Looks like I am getting pretty close but need your help, Again. I will post my first...
4
by: XpatienceX | last post by:
Hi, Can someone help me with this assignment, I am confused of what is needed to be done here. I am suposed to design a program that models a worm's behavior in the following scenario: A...
20
by: Ifoel | last post by:
Hi all, Sorry im beginer in vb. I want making programm looping character or number. Just say i have numbers from 100 to 10000. just sample: Private Sub Timer1_Timer() if check1.value= 1...
6
by: vbwire | last post by:
i use vb 6.0 Option Explicit Dim Error As Double Dim x As Integer Dim y As Double Dim z As Integer
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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,...
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
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...

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.