Hi,
I am trying to create a way where Javascript can do a loop between two Unix Timestamps to print out the dates and some html. I have created a way for this method to work in PHP. However, I need this same method to work in Javascript.
Working PHP:
<?php
// Start date
$date = '01/09/2013';
$start_date = date('l, F j, Y', strtotime($date));
// End date
$end_date = '01/14/2013';
//How many days in between dates
$i = 1;
while (strtotime($date) <= strtotime($end_date)) {
if($i==1)
{
echo '<h3>Set times for the dates listed below:</h3>';
echo '<strong>Day: '.$i.': </strong>'.$start_date.'<br />';
}
else
{
echo '<br /><strong>Day: '.$i.': </strong>'.$date.'<br />';
}
?>
<select class="input-style sch" name="sch_time" size="1">
<option value=""></option>
<?php
for($n = strtotime("08:00"), $e = strtotime("24:00"); $n <= $e; $n += 900)
echo '<option value="'.date("H:i",$n).'">'.date("g:i a",$n).'</option>'."\n";
?>
</select>
-
<select class="input-style sch" name="sch_end_time" size="1">
<option value=""></option>
<?php
for($n = strtotime("08:00"), $e = strtotime("24:00"); $n <= $e; $n += 900)
echo '<option value="'.date("H:i",$n).'">'.date("g:i a",$n).'</option>'."\n";
?>
</select>
<?php
$date = date ("l, F j, Y", strtotime("+1 day", strtotime($date)));
$i++;
}
?>
Javascript:
<script>
$(document).ready(function(){
var startTime = $('input[name="event_sub_stime1"]').val();//value='2013-01-09'
var endTime = $('input[name="event_sub_etime1"]').val();//vaule='2013-01-14'
//Convert Date String into Unix Timestamp
var date_parse = new Date(startTime);
date = date_parse.getTime() / 1000;
var end_parse = new Date(endTime);
edate = end_parse.getTime() / 1000;
//Testing
alert(date+' '+edate);
});
</script>
I would like the Javascript code to print exactly what the PHP is printing out, but of course in Javascript scripting language.
NOTICE: The values will be coming from a form.
Thanks in advance!
-programmer12