Jump to content

getting date start and end


redarrow

Recommended Posts

How do i get a loop to show the date from date start to date end showing all dates avalable

 

 

example

 

<?php

//get todays date
$date_start=date("d-m-y");

//get todays date in a timestamp
$date_start=strtotime($date_start);

//make a timestamp and date to stop by
$date_end= mktime(0, 0, 0, date("d")+7  , date("m"), date("Y"));

//some for loop to get the start date to end date showing all dates

//format the date result from the loop
$date_result=date("y-m-d",$result);

//echo the dates
echo $date_result;

?>

Link to comment
Share on other sites

I would probably start with date_start, and use mktime() to add 1 day until you reach date_end.

 

You can also add 60*60*24 seconds, but apparently that may cause trouble during daylight savings switchovers.  Not that I actually understand what happens to time values during DST :)

Link to comment
Share on other sites

redarrow, I know you know how to write a for loop, as I've seen you write code more advanced than this for other people. Why don't you try something, and then we can help you edit it. btherl suggested a way to do it that will work with your existing code, so just plug it in.

Link to comment
Share on other sites

got no idear dosent work i am stuck no joke?

 

Need help.

 

 

<?php

//get todays date
$date_start=date("d-m-y");

//get todays date in a timestamp
$date_start=strtotime($date_start);

//make a timestamp and date to stop by
$date_end= mktime(0, 0, 0, date("d")+7  , date("m"), date("Y"));

//some for loop to get the start date to end date showing all dates

for($i=$start_date; $i<$end_date; $i++){

$result='".[$i]$date_result."';
}

//format the date result from the loop
$date_result=date("y-m-d",$result);

//echo the dates
echo $date_result;

?>

Link to comment
Share on other sites

dont get it what was said here my current example please help cheers.

 

<?php

$date_start=date("d-m-y");

$date_end= mktime(0, 0, 0, date("d")+7  , date("m"), date("Y"));

$date_result=date("y-m-d",$date_end);


for($i=$date_start; $i<$date_result; $i++){


echo $date_start;
}


?>

Link to comment
Share on other sites

this is something like what you want i think:

 

<?php
//todays date is time()
$date_start = time();

//get 7 days ahead. change 7 to any number of days
$date_end = time() + 24 * 60 * 60 * 7;

//some for loop to get the start date to end date showing all dates
for($i = $date_start; $i < $date_end; $i += 84600){
$out_dates .= date("d-m-y", $i)."<br>";
}

//echo out the dates
echo $out_dates;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.