I'm trying to display dates in a HTML table. I want to display each month, but I failed when the dates go over a month for example: 2015-30-11 to 2015-01-12
They break the table because there are too many <td>'s and I don't know how to display them in the next month.
Each user Has their own dates.
Code:
$month = date(m);
$year = date(Y);
$day = date(d);
if (isset($_GET['month'])) {
$month = $_GET['month'];
}
$days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
echo "<h2>$month-$day-$year</h2>";
echo "<h3>Amount of days: $days </h3>";
$days = $days + 1;
$employee_count = 0;
$sql = "SELECT * FROM employee WHERE inactive = 0";
$result = mysqli_query($con, $sql) or die ('Unable to execute query. ' . mysqli_error($con));
while ($row = mysqli_fetch_assoc($result)) {
$employee_id[] = $row;
$employee_count++;
}
echo "<table border='1'>";
echo "<tablehead>";
echo "<tr>";
for ($j = 0; $j < $days; $j++) {
echo "<th>$j</th>";
}
echo "</tr>";
echo "</tablehead>";
for ($i = 0; $i < $employee_count; $i++) {
echo "<tr>";
$id = $employee_id[$i]['employee_ID'];
$sql = "select * from employee where inactive = 0 and employee_ID = $id";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$employee[] = $row;
}
$name = $employee[0]['name'];
$surname = $employee[0]['surname'];
echo "<td>$surname $name</td>";
$count_absences = 0;
$sql = "select * from absences where employee_FK = $id";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$absences[] = $row;
$count_absences++;
}
$table = $days - 1;
$minus = 0;
for ($l = 0; $l < $table; $l++) {
for ($y = 0; $y < $count_absences; $y++) {
$start = $absences[$y]['start'];
$end = $absences[$y]['end'];
$dStart = new DateTime($start);
$dEnd = new DateTime($end);
$dDiff = $dStart->diff($dEnd);
$diff = $dDiff->days;
$diff = $diff + 1;
$date = $start;
$start_day = date('d', strtotime($date));
$start_day = $start_day - 1;
$start_month = date('m', strtotime($date));
$start_day = $start_day - 1;
if ($start_month == $month && $start_day == $l) {
for ($a = 0; $a < $diff; $a++) {
echo "<td>X</td>";
$l++;
}
}
}
echo "<td></td>";
unset($employee);
}
echo "</tr>";
unset($absences);
}
echo "</table>";
if ($month == 12) {
$next = 1;
} else {
$next = $month + 1;
}
if ($month == 1) {
$previous = 12;
} else {
$previous = $month - 1;
}
echo "<br>";
echo "<button type=\"button\" name=\"previous\" >Previous</button>";
echo "<button type=\"button\" name=\"next\" >Next</button>";
Revise your inner loop like this:
for($l=0;$l<$table;$l++){
$mark = false;
for($y=0; $y<$count_absences; $y++){
$start = $absences[$y]['start'];
$end = $absences[$y]['end'];
$dStart = new DateTime($start);
$dEnd = new DateTime($end);
$dDiff = $dStart->diff($dEnd);
$diff = $dDiff->days + 1;
$start_day = date('d', strtotime($start)) - 1;
$start_month = date('m', strtotime($start));
$lString = $year.'-'.$month.'-'.($l+1);
$lDate = new DateTime($lString);
if($lDate>=$dStart && $lDate<=$dEnd){
$mark = true;
break;
}
}
if($mark){
echo "<td>X</td>";
} else {
echo "<td></td>";
}
unset($employee);
}
That way on each iteration the specific day we're on for the employee will be checked against all date spans of their absence, even if absence spans across months.
I add this snippet:
if ($start_month != $month) {
echo '</tr><tr>';
}
It might be all you need, but I am not sure if that is going to work.
In any case you need to check if you are in a different month to switch to next line. I am not sure where that would be in your code.
<?
$month = date(m);
$year = date(Y);
$day = date(d);
if (isset($_GET['month'])) {
$month = $_GET['month'];
}
$days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
echo "<h2>$month-$day-$year</h2>";
echo "<h3>Amount of days: $days </h3>";
$days = $days + 1;
$employee_count = 0;
$sql = "SELECT * FROM employee WHERE inactive = 0";
$result = mysqli_query($con, $sql) or die ('Unable to execute query. ' . mysqli_error($con));
while ($row = mysqli_fetch_assoc($result)) {
$employee_id[] = $row;
$employee_count++;
}
echo "<table border='1'>";
echo "<tablehead>";
echo "<tr>";
for ($j = 0; $j < $days; $j++) {
echo "<th>$j</th>";
}
echo "</tr>";
echo "</tablehead>";
for ($i = 0; $i < $employee_count; $i++) {
echo "<tr>";
$id = $employee_id[$i]['employee_ID'];
$sql = "select * from employee where inactive = 0 and employee_ID = $id";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$employee[] = $row;
}
$name = $employee[0]['name'];
$surname = $employee[0]['surname'];
echo "<td>$surname $name</td>";
$count_absences = 0;
$sql = "select * from absences where employee_FK = $id";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$absences[] = $row;
$count_absences++;
}
$table = $days - 1;
$minus = 0;
for ($l = 0; $l < $table; $l++) {
for ($y = 0; $y < $count_absences; $y++) {
$start = $absences[$y]['start'];
$end = $absences[$y]['end'];
$dStart = new DateTime($start);
$dEnd = new DateTime($end);
$dDiff = $dStart->diff($dEnd);
$diff = $dDiff->days;
$diff = $diff + 1;
$date = $start;
$start_day = date('d', strtotime($date));
$start_day = $start_day - 1;
$start_month = date('m', strtotime($date));
$start_day = $start_day - 1;
if ($start_month != $month) {
echo '</tr><tr>';
}
if ($start_month == $month && $start_day == $l) {
for ($a = 0; $a < $diff; $a++) {
echo "<td>X</td>";
$l++;
}
}
}
echo "<td></td>";
unset($employee);
}
echo "</tr>";
unset($absences);
}
echo "</table>";
if ($month == 12) {
$next = 1;
} else {
$next = $month + 1;
}
if ($month == 1) {
$previous = 12;
} else {
$previous = $month - 1;
}
echo "<br>";
echo "<button type=\"button\" name=\"previous\" >Previous</button>";
echo "<button type=\"button\" name=\"next\" >Next</button>";
Maybe you should check in your loop that month of current date (in loop) is the same as month of previous date by keeping at the end of every loop the last value of month ($actualMonth). You probably have to setup this value outside the loop with null and ignore this verification if $actualMonth is null. Also, you can start verification after first loop.
If it's different, you have to break your loop. You can compare directly with your $month parameter.
OR
You could restrict your SQL query to get absence only for the month currently displayed.
MySQL :
SELECT * FROM employees WHERE MONTH(date_to_checked) = month_number;
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_month
Related
I have a issue with the return of my multidimensional arrays. For some reason two of them are returned as objects and not arrays when the initialization is fairly the same.
I'm creating a time card and would like to return the % of time an employee was late and on time in a month for the total of past 12 months.
Code:
$eID = $_GET['showLatencyValues'];
//get the last 12 months
$month = time();
for ($i = 1; $i <= 12; $i++) {
$month = strtotime( date( 'Y-m-01' )." -$i months");
$months[] = date("r", $month);
}
$ii = 0;
for($i = 11; $i >= 0; $i--) {
$m = explode(" ", $months[$i]);
$result = $m[2].'. '.$m[3];
$last12months[$ii][0] = $ii;
$last12months[$ii][1] = $result;
$ii++;
}
//set the correct dates
$f = explode(" ", $last12months[0][1]);
$t = explode(" ", $last12months[11][1]);
$from = $f[1].'-'.letterToNumeric($f[0]).'-01';
$days = cal_days_in_month(CAL_GREGORIAN, letterToNumeric($t[0]), $t[1]); // 31
$to = $t[1].'-'.letterToNumeric($t[0]).'-'.$days;
//get the information from database
$sql = mysqli_query($conn, "SELECT DISTINCT `timeIn`,`date` FROM `clock` WHERE `eID`='$eID' AND date BETWEEN '$from' AND '$to'");
$res = mysqli_fetch_array($sql);
$break = explode("-", $res['date']);
$month = $break[1]; //set current month to
$countMonth = 0; //month number
$count = 0; //day number
$sql = mysqli_query($conn, "SELECT min(timeIn) as timeIn,`date` FROM `clock` WHERE `eID`='$eID' AND date BETWEEN '$from' AND '$to' group by date");
while($res = mysqli_fetch_array($sql)) {
$break = explode("-", $res['date']); //get the current selected month
if($month != $break[1]) { //check if current month is the same as selected by database if not then
$countMonth++; //add current month number
$count = 0; //set current day number to 0
$month = $break[1]; //set the current month to whatever is selected by database
}
$timeInData[$countMonth][$count] = $res['timeIn'];
$count++;
}
$count = 0;
for($i = 0; $i < count($timeInData); $i++) {
for($s = 0; $s < count($timeInData[$i]); $s++) {
$firstShift_timeIn = setting($conn, 'timeIn1');
$secondShift_timeIn = setting($conn, 'timeIn2');
$lateConsideredAfter = setting($conn, 'lateAfter');
$actualTime = date("H:i", strtotime($timeInData[$i][$s]));
if($res_shift['shift'] == 1) $considerLateTime = date("H:i", strtotime($firstShift_timeIn." +".$lateConsideredAfter." minutes"));
else $considerLateTime = date("H:i", strtotime($secondShift_timeIn." +".$lateConsideredAfter." minutes"));
if($actualTime > $considerLateTime) $late[$count]++;
else $onTime[$count]++;
}
$count++;
}
if($count != 12) {
$amt = (12-($count))-1;
for($w = 0; $w <= $amt; $w++) {
$onTimeYesData[$w][0] = $w;
$onTimeYesData[$w][1] = 0;
$onTimeNoData[$w][0] = $w;
$onTimeNoData[$w][1] = 0;
}
}
for($q = ($amt+1); $q <= 11; $q++) {
$total = $onTime[($q-($amt+1))] + $late[($q-($amt+1))];
$onTimeYesData[$q][0] = $q;
$onTimeYesData[$q][1] = round(($onTime[($q-($amt+1))]/$total)*100);
$onTimeNoData[$q][0] = $q;
$onTimeNoData[$q][1] = round(($late[($q-($amt+1))]/$total)*100);
}
$response[1] = $last12months;
$response[0] = $onTimeYesData;
$response[2] = $onTimeNoData;
echo json_encode($response[1])."\n\n".json_encode($response[0])."\n\n".json_encode($response[2]);
Output that I receive:
[[0,"Mar. 2019"],[1,"Apr. 2019"],[2,"May. 2019"],[3,"Jun.
2019"],[4,"Jul. 2019"],[5,"Aug. 2019"],[6,"Sep. 2019"],[7,"Oct.
2019"],[8,"Nov. 2019"],[9,"Dec. 2019"],[10,"Jan. 2020"],[11,"Feb.
2020"]]
{"1":[1,90],"2":[2,100],"3":[3,96],"4":[4,91],"5":[5,95],"6":[6,95],"7":[7,100],"8":[8,92],"9":[9,95],"10":[10,89],"11":[11,88]}
{"1":[1,10],"2":[2,0],"3":[3,4],"4":[4,9],"5":[5,5],"6":[6,5],"7":[7,0],"8":[8,8],"9":[9,5],"10":[10,11],"11":[11,13]}
I expect the two other outputs to be in the same format as the first one.
Any help is very much appreciated. Thanks.
I am trying to create an amortization calculator that calculates the declining principal
$x = 1;
$starting_pmt = 26;
$ending_pmt = 36;
$i = 0.0010316264327892;
$p = 410000;
$pmt = 916.84;
$num_pmts = $ending_pmt - $starting_pmt;
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>PMT Num</th>";
echo "<th>Balance</th>";
echo "<th>Principle</th>";
echo "<th>TTL Principle</th>";
echo "<th>Interest</th>";
echo "<th>Payment</th>";
echo "</tr>";
while ( $starting_pmt <= $ending_pmt ) {
echo "<tr><td>";
echo $starting_pmt;
echo "</td><td>";
echo $p;
echo "</td>";
echo "<td>$prin</td>";
echo "<td>$TTLprin</td>";
echo "<td>$interest</td>";
echo "<td>$TTLPmt</td> </tr>";
$starting_pmt = $starting_pmt + 1;
$p = $p -($p*$i);
$prin = $pmt - ($p * $i);
$interest = $pmt - $prin;
$TTLPmt = $prin + $interest;
//$cumTTL = $$pmt - ($p * $i);
$TTLprin = $prin + $prin;
}
echo "</table>";
?>
balance for each payment and the total principle paid between two values. I also want to calculate the interested paid for each payment and the accumulative interest paid between the two values.
This is what I am starting with.
I cannot figure out how to get the loop to do the math during each iteration............... I have been working my original code and I am getting closer. I cannot get the loop to calculate the cumulative total for principal and interest paid.
<?php
$starting_pmt = 1;
$ending_pmt = 10;
$i = 0.0010316264327892;
$p = 410000;
$pmt = 916.84;
$num_pmts = $ending_pmt - $starting_pmt;
while($x < $num_pmts) {
echo "<tr>";
echo "<td>$x</td>";
echo "<td>".$p - ($p*$i)."</td>";
echo "<td></td>";
echo "<td></td>";
echo "<tr>";
$x++;
I get the math. It's getting the while loop to do what I need. It's not calculating the cumulative total for the principle paid.
Here is a way to make an amortization script, you need to pass back what you want your rate, payment date, and all that good stuff. then I am returning an associative array with all the values for each month.
public static function amortizeLoan($principal, $rate, $term, $extra_days, $payment_date){
$payment = self::getPayment($principal,($rate*100),$term,$extra_days);
$MonthlyInterestRate = $rate / 12;
$Multiplier = 1 + $MonthlyInterestRate;
$TermRate = 1;
for($x=0;$x<$term;$x++){
$TermRate = $TermRate * $Multiplier;
}
$Days = $extra_days - 30;
$oddDayInt = $Days > 0 ? round($principal * ($rate / 365.25) * $Days,2) : 0;
$amortization = [];
$total_interest = 0;
$total_principal = 0;
$remaining_principal = $principal;
$compareDay = date('d', strtotime($payment_date));
for($x=0;$x<$term;$x++){
$this_int_paid = round((($rate)/12) * $remaining_principal,2);
if($x==0){$this_int_paid += $oddDayInt;}
$this_princ_paid = round($payment - $this_int_paid,2);
$this_rem_princ = round($remaining_principal - $this_princ_paid,2);
if($x == ($term-1)){
if($this_rem_princ < 0){
$this_princ_paid-=abs($this_rem_princ);
$payment=round($this_int_paid+$this_princ_paid,2);
}else{
$this_princ_paid+=$this_rem_princ;
$payment=round($this_int_paid+$this_princ_paid,2);
}
}
$remaining_principal -= $this_princ_paid;
$total_interest += $this_int_paid;
$total_principal += $this_princ_paid;
// *** If month days < payment date, payment date falls on the last day of that month.***
$nextMonth = strtotime("last day of next month", strtotime($payment_date));
$lastDayNextMonth = date('d', $nextMonth);
if ($compareDay >= $lastDayNextMonth) {
$payment_date_time = $x ? $nextMonth : strtotime($payment_date);
} else {
$payment_date_time = $x ? strtotime("+1 month", strtotime($payment_date)) : strtotime($payment_date);
}
if ($lastDayNextMonth > date('d', strtotime($payment_date)) && date('t', strtotime($payment_date)) < $compareDay) {
$date = date('Y-m-d', $nextMonth);
$newDate = date_create($date);
$newDate->format('Y-m-d');
$finalDate = date_date_set(
$newDate,
date_format($newDate, 'Y'),
date_format($newDate, 'm'),
$compareDay
);
$formatedDate = $finalDate->format('m/d/y');
$payment_date_time = strtotime($formatedDate);
}
$payment_date = gmdate("Y-m-d", $payment_date_time);
$amortization[] = [
"payment"=>($x+1),
"amount"=>$payment,
"principal"=>$this_princ_paid,
"interest"=>$this_int_paid,
"total_principal"=>$total_principal,
"total_interest"=>$total_interest,
"remaining_balance"=>round($remaining_principal,2),
"payment_date"=>$payment_date
];
}
return $amortization;
}
I've created and array and it works just how I wanted it to. The final part I wanted to attempt is to output the data horizontally but not sure how to.
<?php
$date = "2015-11-25";
$t = 0;
$startdate = "2009/06/01";
$start = strtotime($date);
$currentdate = $start;
$times_table = array();
for($i = 0; $i <= 3; $i++){
$times_table[$i] = array();
}
echo "<pre>";
for($i = 0; $i <= 3; $i++){
for($j = 0; $j <= 2; $j++){
if ($j == 0){
$times_table[$i][$j]= "Version 4" ;
}
else if ($j == 1){
$cur_date = date('Y/m/d', $currentdate);
$currentdate = strtotime('+1 month', $currentdate);
$times_table[$i][$j]= $cur_date ;
}
else{
$times_table[$i][$j]= "good" ;
}
}
}
print_r($times_table);
echo "</pre>";
?>
I'm not sure what you are trying to accomplish, but this looks like it should be in a table. For example:
<?php
$date = "2015-11-25";
$t = 0;
$startdate = "2009/06/01";
$start = strtotime($date);
$currentdate = $start;
$times_table = array();
for($i = 0; $i <= 3; $i++){
$times_table[$i] = array();
}
for($i = 0; $i <= 3; $i++){
for($j = 0; $j <= 2; $j++){
if ($j == 0){
$times_table[$i][$j]= "Version 4" ;
}
else if ($j == 1){
$cur_date = date('Y/m/d', $currentdate);
$currentdate = strtotime('+1 month', $currentdate);
$times_table[$i][$j]= $cur_date ;
}
else{
$times_table[$i][$j]= "good" ;
}
}
}
echo '<table>';
echo '<tr><th>Version #</th><th>Date</th><th>Status</th></tr>';
foreach($times_table as $times){
echo '<tr>';
foreach($times as $t){
echo '<td>',$t,'</td>';
}
echo '</tr>';
}
echo '</table>';
?>
I should note that I would strongly discourage outputting raw data such as with print_r or var_dump for anything but debugging purposes that cannot find their way into the real world. It can be very bad for security.
I'm currenty looking into this tutorial to create a calendar. The only problem I have atm is that my months are in english instead of dutch. How can I change the output of 'july' to 'juli' ?
<?php
$vandaag = date("d"); // Current day
$maand = date("m"); // Current month
$jaar = date("Y"); // Current year
$dagen = cal_days_in_month(CAL_GREGORIAN,$maand,$jaar); // Days in current month
$vorigemaand = date("t", mktime(0,0,0,$maand-1,1,$jaar)); // Days in previous month
$begin = date("N", mktime(0,0,0,$maand,1,$jaar)); // Starting day of current month
$einde = date("N", mktime(0,0,0,$maand,$dagen,$jaar)); // Finishing day of current month
$vorigestart = $begin - 1; // Days of previous month in calander
$counter = 1;
$volgendeMaandCounter = 1;
if($begin > 5){ $rows = 6; }else {$rows = 5; }
for($i = 1; $i <= $rows; $i++){
echo '<tr class="week">';
for($x = 1; $x <= 7; $x++){
if(($counter - $begin) < 0){
$date = (($vorigemaand - $vorigestart) + $counter);
$class = 'class="blur"';
}else if(($counter - $begin) >= $dagen){
$date = ($volgendeMaandCounter);
$volgendeMaandCounter++;
$class = 'class="blur"';
}else {
$date = ($counter - $begin + 1);
if($vandaag == $counter - $begin + 1){
$class = 'class="today"';
}
}
echo '<td '.$class.'><a class="date">'. $date . '</a></td>';
$counter++;
$class = '';
}
echo '</tr>';
}
?>
Thanks in advance!
try with this code:
setlocale(LC_TIME, 'de_DE', 'deu_deu');
/* print test date string */
echo strftime("%A, %d. %B %Y");
I am working on a calendar in PHP. With the calendar, I am able to query a mysql database and it will show the number of events for each day. The problem I'm having is that it is showing the start and end dates but i need it to also show all the days inbetween.Thus, showing that the days inbetween are also occupied. My current Table has DepDate (departure) AND RetDate (Return Date). Im thinking this has to be done through the mysql query. Any help would be awesome! Thanks buds
<script>
function goLastMonth(month, year, keyname){
if(month == 1) {
--year;
month = 13;
}
--month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
var keyname = "<?php echo $searchTerm; ?>";
if(monthlength <=1){
monthstring = "0" + monthstring;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year+"&keyname="+keyname;
}
function goNextMonth(month, year, keyname){
if(month == 12) {
++year;
month = 0;
}
++month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
var keyname = "<?php echo $searchTerm; ?>";
if(monthlength <=1){
monthstring = "0" + monthstring;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year+"&keyname="+keyname;
}
</script>
</head>
<?php
if (isset($_GET['day'])){
$day = $_GET['day'];
} else {
$day = date("j");
}
if(isset($_GET['month'])){
$month = $_GET['month'];
} else {
$month = date("n");
}
if(isset($_GET['year'])){
$year = $_GET['year'];
}else{
$year = date("Y");
}
$currentTimeStamp = strtotime( "$year-$month-01");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$currentTimeStamp = strtotime( "$day-$month-$year"); // added this to reset this value for prev* and next* code
$counter = 0;
?>
<?php
include ('plane.css');
/* ------------------------------------------------------------Calendar Creation---------------------------------------------------------------------- */
include ('planeh.html');
?>
<?php
//get previous month
$prevMonth = $month - 1;
$prevYear = $year;
if($prevMonth <= 0){
$prevMonth = 12;
$prevYear--;
}
$pMonthStr = "" + $prevMonth;
if(strlen($pMonthStr) <= 1)
$pMonthStr = "0" + $pMonthStr;
//get num of day for previous month
$previousTimeStamp = strtotime( "01-$pMonthStr-$prevYear");
$prevNumDays = date("t", $previousTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
for($i = 1; $i < $numDays+1; $i++, $counter++){
$timeStamp = strtotime("$year-$month-$i");
if($i == 1) {
$firstDay = date("w", $timeStamp);
for($j = 0; $j < $firstDay; $j++, $counter++) {
$prevDay = $prevNumDays-$firstDay+$j+1;
echo "<td class = td3><div id = prev>$prevDay</div></td>";
}
}
if($counter % 7 == 0) {
echo"</tr><big></big><tr>";
}
/* Up to this point, everything is the development of the calendar */
$monthstring = $month;
$monthlength = strlen($monthstring);
$daystring = $i;
$daylength = strlen($i);
if($daylength <=0){
$daystring = "0".$daystring;
}
// links and date located on calendar
$todaysDate = date("m/d/y");
/* Indicates date located on calendar */
echo "<td align = center class = td3><div class = button>".$i."</a></div>";
$sqlEvent2 = mysql_query("select * FROM trips where DepDate = '".$year."-".$month."-".$i."'");
$num_rows = mysql_num_rows($sqlEvent2);
if(mysql_errno()){
echo "MySQL error ".mysql_errno().": "
.mysql_error()."\n<br>When executing <br>\n$query\n<br>";
}
echo '<div id="button">';
echo "<a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$i."&year=".$year."&v=true' >".$num_rows."</a></td>";
echo '</div>';
}
echo "<tr>";
echo"</table>";
?>
<div id ="menu">
<?php include ('menu2.php');?>
</ul>
</div>
</div>
</tr>
</body>
</html>
All you need here is to reference the MySQL date and time functions, specifically datediff: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_datediff
An example would be:
SELECT start_dt, end_dt, datediff(end_dt, start_dt) as days_elapsed
FROM my_table
where start_dt and end_dt are both date valued.