for some reason the Php date isn't working on the server.
Here is the function for displaying the tip of the day. I am using the codeigniter framework. In the function below i am trying to print the day of year ($doy). When i go to the url and try to access the tip function it shows a blank page. The day of year is not printed.
public function tip(){
$idCount = $this->db->query('SELECT Count(*) AS COUNT FROM clickmag_tip')->result();
$total = $idCount[0]->COUNT;
$time = time();
$doy = mdate('%z', $time);
echo $doy;
//$day_of_year = date('z',time());
//$doyear = date("z") + 1;
//echo $doyear;
$s = mktime(date("G") + 1);
print date("Y/m/d h:i:s a", $s);
if($total > 0){
$offset = $doy % $total ;
}
$data = $this->db->query('SELECT * FROM table_tip LIMIT 1 OFFSET '. $offset);
header('Content-type: text/json');
header('Content-type: application/json');
echo json_encode($data->result());
}
What do you think is the problem? I talked to the server people but they also don't know.
How can i solve this?
Thanks in advance!
You must output all headers before outputting anything.
You have both:
echo $doy;
AND
print date("Y/m/d h:i:s a", $s);
Before
header('Content-type: text/json');
header('Content-type: application/json');
That is what's causing the blank page.
Related
I am trying to get data from some particular range of dates,
<?php
function index_finder()
{
$strStart = '2021-01-02';
$strEnd = '2021-08-28';
$dteStart = new DateTime($strStart);
$dteEnd = new DateTime($strEnd);
$dteDiff = $dteStart->diff($dteEnd);
$date = $dteDiff->format("%m month\n");
if ($date > 6)
{
$curl = 'https://localhost:9200/studio-.'$strStart'.,studio-.'$strEnd'./_search?pretty';
print $curl;
}
}
if date range is more then 6 months, then need to call this curl with start and end date,
I am trying to insert the startdate and end date in the url.
Kindly help me out to pass the dates in the url.
Thanks in advance
Replace this :
$curl = 'https://localhost:9200/studio-.'$strStart'.,studio-.'$strEnd'./_search?pretty';
By this :
$curl = 'https://localhost:9200/studio-' . $strStart . ',studio-' . $strEnd . '/_search?pretty';
Guys we have a website that records the travel time of the vehicle. We have different kinds of reports. The problem is that our 2 reports is not the same on the last data. I think our problem is on the syntax on the display of our report.
here are sample screenshots of our reports. the KMLOG and the Daily Report. our problem is we need to display the output of the
]
if($endidling){
$total_idling=xtimediff($s_idling_date." ".$s_idling_time,$e_idling_date." ".$e_idling_time);
//if ($total_idling>=($entry['ilimit']*60)){
if($s_idling_date==$e_idling_date){
$data[$myCount]["xtype"] = "idling";
$data[$myCount]["dur"] = sec2hms($total_idling);
$data[$myCount]["sdate"] =date('M d',strtotime($s_idling_date));
$data[$myCount]["stime"] =$s_idling_time." to ".$e_idling_time;
$data[$myCount]["location"] = $location;
$myCount +=1;
}
else{
//$data[$myCount]["stime"] =$s_idling_time." to ".$e_idling_time." of ".date('M d',strtotime($e_idling_date)) ;
$day_def=def_date($s_idling_date,$e_idling_date);
for($day=0;$day<=$day_def;$day++){
if($day==0){
$ddur = xtimediff($s_idling_date." ".$s_idling_time,$s_idling_date." ".$gabi);
$data[$myCount]["stime"] =$s_idling_time." to ".$gabi;
$next_day=$s_idling_date;
}
elseif($day==$day_def){
$ddur = xtimediff($e_idling_date." ".$umaga,$e_idling_date." ".$e_idling_time);
$data[$myCount]["stime"] =$umaga." to ".$e_idling_time;
$next_day = date('Y-m-d', strtotime($next_day . ' +1 day'));
}
else{
$ddur = xtimediff($s_idling_date." ".$umaga,$s_idling_date." ".$gabi);
$data[$myCount]["stime"] =$umaga." to ".$gabi;
$next_day = date('Y-m-d', strtotime($next_day . ' +1 day'));
}
//if($day==0) $ddur= xtimediff($s_off_date." ".$s_off_time,$e_off_date." ".$e_off_time);
$data[$myCount]["xtype"] = "idling";
$data[$myCount]["dur"] = sec2hms($ddur);
$data[$myCount]["sdate"] =date('M d',strtotime($next_day));
$data[$myCount]["location"] = $location;
$myCount +=1;
}
}
//}
$endidling=false;
$total_idling=0;
}
How to calculate a date before 10 days of every month end ?Am using codeigniter platform.
I need to check whether a date is within 10 days before the end of every month.
Please help
You can try using date_modify function for example see this php documentation
http://php.net/manual/en/datetime.modify.php
i need to check whether a date is within10 days before the end of a month
function testDate($date) {
$uDate = strtotime($date);
return date("m", $uDate) != date("m", strtotime("+10 days", $uDate));
}
echo testDate("2016-03-07") ? "Yes" :"No"; // No
echo testDate("2016-03-27") ? "Yes" :"No"; // Yes
you can create a library with this
class Calculate_days{
function __construct() {
parent::__construct();
}
function calculate( $to_day = date("j") ){
$days_month = date("t");
$result = (int) $days_month - $to_day;
if( $result <= 10){
$result = array("type" => TRUE, "missing" => $result . 'days');
return $result;
}
else{
$result = array("type" => FASLE, "missing" => $result . 'days');
return $result;
}
}
}
controller.php
function do_somthing(){
$this->load->library('Calculate_days');
$result = $this->Calculate_days->calculate(date("j"));
var_dump($result);
}
I am exporting result of a query in a csv file. The code is as shown below:
$query = "SELECT DATE(punchdetails.punchin) as punchday,punchdetails.punchin,punchdetails.punchout,employeedetails.employeename
FROM punchdetails join(employeedetails) ON punchdetails.employeeid=employeedetails.employeeid
AND punchdetails.employeeid=$employeeid AND DATE(punchdetails.punchin)=$fromdate";
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
ini_set('display_errors',1);
$private=1;
error_reporting(E_ALL ^ E_NOTICE);
$select_c = mysql_query($query);
while ($row = mysql_fetch_array($select_c))
{
$intime = strtotime($row['punchin']);
$mysqlintime = date( 'H:i:a', $intime );
$outtime = strtotime($row['punchout']);
$mysqlouttime = date( 'H:i:a', $outtime );
$result.=$row['employeename'].','.$row['punchday'].','.$mysqlintime.','.$mysqlouttime;
$result.="\n";
echo $result;
}
When I execute the query it is returning records correctly. But when I download the result of the query as csv file, the records are getting duplicated. I am getting the resultant csv file data as shown below:
Sonu,2013-09-26,10:55:am,11:12:am
Sonu,2013-09-26,10:55:am,11:12:am
Kristo,2013-09-26,11:23:am,11:24:am
I am not getting what is the problem. Can anybody help me to solve this? Thanks in advance.
I see the problem
you concatinate the result with each row, then echo. So, each time you echo - you will echo all the previous results + the current result.
Either, change:
$result.=$row['employeename'].','.$row['punchday'].','.$mysqlintime.','.$mysqlouttime;
$result.="\n";
to:
echo $row['employeename'].','.$row['punchday'].','.$mysqlintime.','.$mysqlouttime;
echo "\n";
or move the echo $result; outside the while loop
You need to echo $result outside of the while loop:
$result='';
while ($row = mysql_fetch_array($select_c))
{
$intime = strtotime($row['punchin']);
$mysqlintime = date( 'H:i:a', $intime );
$outtime = strtotime($row['punchout']);
$mysqlouttime = date( 'H:i:a', $outtime );
$result.=$row['employeename'].','.$row['punchday'].','.$mysqlintime.','.$mysqlouttime;
$result.="\n";
}
echo $result;
Trying to setup a page that auto updates based on the users date/time.
Need to run a promotion for 2 weeks and each day it needs to change the displayed image.
Was reading through http://www.thetricky.net/php/Compare%20dates%20with%20PHP to get a better handle on php's time and date functions.Somewhat tricky to test, but I basically got stuck on:
<?php
$dateA = '2012-07-16';
$dateB = '2012-07-17';
if(date() = $dateA){
echo 'todays message';
}
else if(date() = $dateB){
echo 'tomorrows message';
}
?>
I know the above function is wrong as its setup, but I think it explains what I am aiming for.
Time is irrelevant, it needs to switch over at midnight so the date will change anyway.
You seem to need this:
<?php
$dateA = '2012-07-16';
$dateB = '2012-07-17';
if(date('Y-m-d') == $dateA){
echo 'todays message';
} else if(date('Y-m-d') == $dateB){
echo 'tomorrows message';
}
?>
you want
<?php
$today = date('Y-m-d')
if($today == $dateA) {
echo 'todays message';
} else if($today == $dateB) {
echo 'tomorrows message';
}
?>
I would go a step back and handle it via file names. Something like:
<img src=/path/to/your/images/img-YYYY-MM-DD.jpg alt="alternative text">
So your script would look something like this:
<img src=/path/to/your/images/img-<?php echo date('Y-m-d', time()); ?>.jpg alt="alternative text">
If you're going to do date calculations, I'd recommend using PHP's DateTime class:
$promotion_starts = "2012-07-16"; // When the promotion starts
// An array of images that you want to display, 0 = the first day, 1 = the second day
$images = array(
0 => 'img_1_start.png',
1 => 'the_second_image.jpg'
);
$tz = new DateTimeZone('America/New_York');
// The current date, without any time values
$now = new DateTime( "now", $tz);
$now->setTime( 0, 0, 0);
$start = new DateTime( $promotion_starts, $tz);
$interval = new DateInterval( 'P1D'); // 1 day interval
$period = new DatePeriod( $start, $interval, 14); // 2 weeks
foreach( $period as $i => $date) {
if( $date->diff( $now)->format("%d") == 0) {
echo "Today I should display a message for " . $date->format('Y-m-d') . " ($i)\n";
echo "I would have displayed: " . $images[$i] . "\n"; // echo <img> tag
break;
}
}
Given that the promotion starts on 07-16, this displays the following, since it is now the second day of the promotion:
Today I should display a message for 2012-07-17 (1)
I would have displayed: the_second_image.jpg