I have made a Register and Login Application with CodeIgniter 3 and Bootstrap.
I am showing all the users in a view:
<table class="table table-striped table-bordered">
<thead>
<tr>
<th class="col-md-1">ID</th>
<th class="col-md-3">Full name</th>
<th class="col-md-6">Email</th>
<th class="col-md-4">Date created</th>
<th class="col-md-4">Date updated</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo $user->id ?></td>
<td><?php echo $user->fname . " " . $user->lname; ?></td>
<td><?php echo $user->email; ?></td>
<td><?php echo $user->created_at ?></td>
<td><?php echo $user->updated_at ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
I want the Date created and Date updated columns to be formatted nicely: March 10 2001, at 15:16:03.
I have loaded the date helper.
What shall I write in the view to get a "pretty" date and time format like that mentioned above?
You could try this way
Example only
<?php echo date('M d Y');?> at <?php echo date('H:i:s', strtotime('15:16:03'));?>
Prints
January 14 2018 at 15:16:03
A full, pretty date and time format Sunday, Nov 19, 2017 at 00:34:36 will be output by writing:
<?php echo nice_date($user->created_at, 'l, M d, Y') . ' at '. nice_date($user->created_at, 'H:i:s'); ?>
And Nov 19, 2017 at 00:34:36 will be output by writing:
<?php echo nice_date($user->created_at, 'M d, Y') . ' at '. nice_date($user->created_at, 'H:i:s'); ?>
Related
I am using the GAPI class (gapi.class.php) for Google Analytics API.
This is the code:
<?php
require 'gapi.class.php';
define('ga_profile_id', 'your profile id');
$ga = new gapi("XXXXXXXX#developer.gserviceaccount.com", "key.p12");
$filter = 'country == United States && browser == Firefox || browser == Chrome';
$ga->requestReportData(ga_profile_id, array('browser', 'browserVersion'), array('pageviews', 'visits'), '-visits', $filter);
?>
<table>
<tr>
<th>Browser & Browser Version</th>
<th>Pageviews</th>
<th>Visits</th>
</tr>
<?php
foreach($ga->getResults() as $result):
?>
<tr>
<td><?php echo $result ?></td>
<td><?php echo $result->getPageviews() ?></td>
<td><?php echo $result->getVisits() ?></td>
</tr>
<?php
endforeach
?>
</table>
<table>
<tr>
<th>Total Results</th>
<td><?php echo $ga->getTotalResults() ?></td>
</tr>
<tr>
<th>Total Pageviews</th>
<td><?php echo $ga->getPageviews() ?>
</tr>
<tr>
<th>Total Visits</th>
<td><?php echo $ga->getVisits() ?></td>
</tr>
<tr>
<th>Result Date Range</th>
<td><?php echo $ga->getStartDate() ?> to <?php echo $ga->getEndDate() ?></td>
</tr>
</table>
But I can't find how to change the date ranges.
By default, it's showing the status from 2014 to today — I think it's the life of the analytics account.
There is a similar question but it's for an older version, which is not working now.
Thank you.
Ok this worked
$start_date = ("2017-11-01");
$end_date = ("today");
$ga->requestReportData(ga_profile_id, array('browser', 'browserVersion'), array('pageviews', 'visits'), '-visits', $filter,$start_date,$end_date);
I tried to highlight records whose certain columns have some values other than NULL. I'm using dataTable plugin.
<table class="table table-striped table-hover" id="checkin-checkout-record-table">
<thead>
<tr>
<th>Employee Name</th>
<th>Check-in-date</th>
<th>Check-in-time</th>
<th>Check-out-date</th>
<th>Check-out-time</th>
<th class="col-lg-2">Late Check-in Remarks</th>
<th class="col-lg-2">Early Check-out Remarks</th>
</tr>
</thead>
<tbody>
<?php
foreach ($checkinCheckoutList as $member): ?>
<tr <?php
if(isset($member['early_checkout_remarks']) ||isset($member['delayed_checkin_remarks']))
{?>
style="background-color:red;"
<?php } ?> >
<td><?php echo $member['fullname'] ?></td>
<td> <?php echo $member['checkin_date']; ?></td>
<td> <?php echo $member['checkin_time']; ?></td>
<td><?php echo $member['checkout_date']; ?></td>
<td><?php echo $member['checkout_time']; ?></td>
<td><?php echo $member['delayed_checkin_remarks']; ?></td>
<td><?php echo $member['early_checkout_remarks']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
But the result is not as expected. Some records are not highlighted. This works well with other normal table. Please help.
$payment_date is date from which I want to subtract 1 month.
how could I do ?
<table class="table table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>Payment Month</th>
<th>Payment Date</th>
<th>Gross Salary </th>
<th>Total Deduction</th>
<th>Net Salary</th>
<th>Advance Salary</th>
<th>Incentive</th>
<th>Fine Deduction</th>
<th>Payment Amount</th>
<th class="hidden-print">Details</th>
</tr>
</thead>
<tbody>
<?php
if (!empty($payment_history)): foreach ($payment_history as $v_payment_history) :
?>
<tr>
<td><?php echo date('F-Y', strtotime($v_payment_history->payment_for_month)); ?></td>
<td><?php echo date('d-M-y', strtotime($v_payment_history->payment_date)); ?></td>
<td><?php echo $gross = $v_payment_history->basic_salary + $v_payment_history->house_rent_allowance + $v_payment_history->medical_allowance + $v_payment_history->special_allowance + $v_payment_history->fuel_allowance + $v_payment_history->phone_bill_allowance + $v_payment_history->other_allowance; ?></td>
<td><?php echo $deduction = $v_payment_history->tax_deduction + $v_payment_history->provident_fund + $v_payment_history->other_deduction; ?></td>
<td><?php echo $net_salary = $gross - $deduction; ?></td>
<td><?php echo $v_payment_history->award_amount; ?></td>
<td><?php echo $v_payment_history->incentive; ?></td>
<td><?php echo $v_payment_history->fine_deduction; ?></td>
<td><?php echo $v_payment_history->payment_amount; ?></td>
<td class="hidden-print"><?php echo btn_view('admin/payroll/salary_payment_details/' . $v_payment_history->salary_payment_id) ?></td>
</tr>
<?php
endforeach;
?>
<?php else : ?>
<tr>
<td colspan="9">
<strong>There is no data for display</strong>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
$payment_date is date from which I want to subtract 1 month.
how could I do ? I want payment only of last month from the month I'm giving payment
Easy!
<?php
$date = new DateTime();
$date->modify('-1 month');
echo $date->format('Y-m-d H:i:s');
See it here https://3v4l.org/UWaGY
You can also feed in a date string as a constructor. new DateTime('2014-09-18');
#LEARNER try it like this, check the output and code online here https://eval.in/806939:
<?php
//suppose that date is 2017/05/29
$yourDate = strtotime('2017/05/29 -1 month'); // substract 1 month from that date and converting it into timestamp
$desiredDate = date("Y-m-d", $yourDate);
echo $desiredDate;
?>
I want chane column name date in to Day i change it to like this but it is error how i chane it to day when displaying data.
<tr>
<td width="" class="rounded" scope="col"><?php echo $row['date as day']; ?></td>
</tr>
This is normal code
</tr>
<tr>
<td width="" class="rounded" scope="col"><?php echo $row['date']; ?></td>
</tr>
I think you mean echo the day of the week. You would use the date function.
If your date is a date/time, not a timestamp you would use strtotime() to make it a timestamp first.
<?php echo date("D", strtotime($row['date'])); ?>
Will output Wed if it's a Wednesday
<?php echo date("l", strtotime($row['date'])); ?>
Will output Wednesday if it's a Wednesday. That's a lower case L not a number 1.
Query:
SELECT date as day FROM table;
and then :
<tr>
<td width="" class="rounded" scope="col"><?php echo $row["day"]; ?></td>
</tr>
HTH.
Okay, I'm sure there's a way to do this but I'm suffering from sleep deprivation and could really use some help.
Here's what I need. I have a table with headers and rows of data listed underneath - it looks great but, I need to add a table row between the rows of data when the month changes to separate out the months.
Here's what I have:
Date Time Event
08-31-2013 6:00 pm EST Horseshoe Tourney
09-07-2013 8:00 pm EST Movie Night
09-28-2013 5:00 pm EST Dinner on the Quad
10-12-2013 4:30 pm EST Sing-a-long
10-31-2013 7:00 pm EST Halloween Party
11-14-2013 4:00 pm EST Hay Ride
Here's what I need:
Date Time Event
AUGUST (to span the whole table row)
08-31-2013 6:00 pm EST Horseshoe Tourney
SEPTEMBER (to span the whole table row)
09-07-2013 8:00 pm EST Movie Night
09-28-2013 5:00 pm EST Dinner on the Quad
OCTOBER (to span the whole table row)
10-12-2013 4:30 pm EST Sing-a-long
10-31-2013 7:00 pm EST Halloween Party
NOVEMBER (to span the whole table row)
11-14-2013 4:00 pm EST Hay Ride
Any help would be greatly appreciated. Below is code I'm using to create the table now.
<table style="width: 100%;">
<thead>
<tr style="background-color:#8a0028; color:white;">
<th style="background-color:#8a0028; color:white; text-align:left;">Date</th>
<th style="background-color:#8a0028; color:white; text-align:left;">Time</th>
<th style="background-color:#8a0028; color:white; text-align:left;">Event</th>
</tr>
</thead>
<tbody>
<?php
// Write rows
mysql_data_seek($result, 0);
while ($row = mysql_fetch_assoc($result)) {
?>
<tr>
<td><?php echo date("M d, Y", strtotime($row['date']));?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['event'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
mysql_free_result($result);
?>
Here's what ended up working for me! Sure do appreciate the help!
<?php
// Write rows
mysql_data_seek($result, 0);
$month='';
while ($row = mysql_fetch_assoc($result)) {
if(date("F", strtotime($row['date']))!==$month){
$month=date("F", strtotime($row['date'])); ?>
<tr><td colspan="3"><?= $month ?></td></tr>
<?php
}
?>
<tr>
<td><?php echo date("M d, Y", strtotime($row['date']));?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['event'];?></td>
</tr>
<?php
$month=date("F", strtotime($row['date']));
}
?>
</tbody>
</table>
<?php
mysql_free_result($result);
?>
Try this:
<table style="width: 100%;">
<thead>
<tr style="background-color:#8a0028; color:white;">
<th style="background-color:#8a0028; color:white; text-align:left;">Date</th>
<th style="background-color:#8a0028; color:white; text-align:left;">Time</th>
<th style="background-color:#8a0028; color:white; text-align:left;">Event</th>
</tr>
</thead>
<tbody>
<?php
// Write rows
mysql_data_seek($result, 0);
$month='';
while ($row = mysql_fetch_assoc($result)) {
if(date("F", strtotime($row['date']))!==$month){
$month=date("F", strtotime($row['date'])); ?>
<tr><td colspan="3"><?= $month ?></td></tr>
<?php
}
?>
<tr>
<td><?php echo date("M d, Y", strtotime($row['date']));?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['event'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
mysql_free_result($result);
?>
I'd suggest something like this:
Essentially, at the beginning of each loop, you're testing to see if the month is different from the previous one. If it is, you output a new row.
<?php
mysql_data_seek($result, 0);
$last_month = '';
while ($row = mysql_fetch_assoc($result)) {
?>
<?php if (date("M", strtotime($row['month'])) != $last_month): ?>
<tr>
<td colspan="4"><?php echo date("M", strtotime($row['month'])); ?></td>
</tr>
<?php endif; ?>
<tr>
<td><?php echo date("M d, Y", strtotime($row['date']));?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['event'];?></td>
</tr>
<?php
$last_month = date("M", strtotime($row['month']));
}
?>