How can someone print fullcalendar or export fullcalendar in PDF or Excel format?
For example:
Input:
Start Date: 01 Jan 2020
End Date: 31 Dec 2020
On click of button it will get all of the events between given date ranges and populate it to the fullcalendar
There will be something like...
26th January 2020 which will have an event - Australia Day
14th February 2020 which will have an event - Valentines day
...
...
25th December 2020 which will have an event - X-Mas Day
As you can see there will be multiple events in different months and what I am looking for is printing or exporting this fullcalendar in a single page with all 12 number of months.
Your response will help many.
You can use the below sample code by editing , hope it helps
<?php
header("Content-Type: text/html; charset=iso-8859-9");
header("Content-Type: text/html; charset=windows-1254");
header("Content-Type: text/html; charset=x-mac-turkish");
$today = date("d-m-Y");
// Defines the name of the export file "codelution-export.xls"
header("Content-Disposition: attachment; filename=$today-BOOK.xls");
$date = '2020-05-01';
//get end date of month
$end = '2020-05-' . date('t', strtotime($date));
include("../../DATABASE.php");
?>
<table>
<tr>
<td>PERSONAL</td>
<?php
while(strtotime($date) <= strtotime($end)){
$day_num = date('d', strtotime($date));
$day_name = date('l', strtotime($date));
$date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
echo "<td>$day_num <br/> $day_name</td>";
}
?>
</tr>
<?php
//get end date of month
$hsql=mysql_query("select * from XXXUSER");
while($hyaz=mysql_fetch_array($hsql)){
$firstname=$hyaz["firstname"];
$kullanicidi=$hyaz["id"];
echo "<tr>";
echo "<td>$firstname</td>";
$fromdate = '2020-06-01';
$todate = '2020-06-' . date('t', strtotime($fromdate));
while(strtotime($fromdate) <= strtotime($todate)) {
$geneltarih = date('Y-m-d', strtotime($fromdate));
$fromdate = date("Y-m-d", strtotime("+1 day",strtotime($fromdate)));
$xxxsql = mysql_fetch_array(mysql_query("select * from XXXSCHEDULE where kaynakcodu='$kullanicidi' and start_event='$geneltarih'"));
$title = $xxxsql["title"];
echo " <td>$title</td>";
}
echo "</tr>";
}
?>
</table>
Related
I'm trying to display some reservations from the database into bootstrap year calendar but each reservation is offset with +1 month.
For example: 28 Nov, 2019 - 01 Dec, 2019 will be displayed like: 28 Dec, 2019 - 01 Jan, 2020
The only solution will be to add -1 month but in this case reservations from Dec-Jan will jump with one year and the 2020 will be unusable.
Did anyone meet this situation ?
.ready(function(){
var currentYear = new Date().getFullYear();
jQuery('.calendar')
.calendar({
style : 'background',
alwaysHalfDay : true,
enableContextMenu : true,
enableRangeSelection: true,
dataSource: [
<?php
$bookings = $method->has_get_booking_of_room($room_id);
foreach($bookings as $row) : //break;
?>
{
booking_id: '<?php echo $row["booking_id"];?>',
startDate : new Date(<?php echo date("Y", $row['checkin_timestamp']);?>, <?php echo date("n", $row['checkin_timestamp']);?>, <?php echo date("j", $row['checkin_timestamp']);?>),
endDate : new Date(<?php echo date("Y", $row['checkout_timestamp']);?>, <?php echo date("n", $row['checkout_timestamp']);?>, <?php echo date("j", $row['checkout_timestamp']);?>)
},
<?php
endforeach;
?>
]
});
});
<?php
$outerarray = array();
$myeventsmodels=Events::model()->findAll();
foreach($myeventsmodels as $myeventsmodel{
$innerarray=array();
$stop_date=date('Y-m-d H:i:s',strtotime($stop_date.'+1 day'));
$innerarray['title']=$myeventsmodel->title;
$innerarray['start']=$myeventsmodel($date)->start_date;
$innerarray['end']=$myeventsmodel->end_date;
$innerarray['url']='/uobportal/#/event';
$outerarray[]=$innerarray;
}
$events=json_encode($outerarray);
?>
You can try like this :
$stop_date = new DateTime('2009-02-15 10:21:00');
echo 'date before day adding: ' . $stop_date->format('Y-m-d H:i:s');
$stop_date->modify('+1 day');
echo 'date after adding 1 day: ' . $stop_date->format('Y-m-d H:i:s');
You can use date_add function here the example:
$stop_date = "2013-03-15";
date_add($stop_date ,date_interval_create_from_date_string("5 days"));
echo date_format($stop_date,"Y-m-d");
the output will be:
2013-03-20
Reference https://www.w3schools.com/php/func_date_date_add.asp
or create a new Date object with existing date plus the number of days you want to add like this:
$stop_date = "2010-09-17";
echo date('Y-m-d', strtotime($stop_date. ' + 1 days'));
echo date('Y-m-d', strtotime($stop_date. ' + 2 days'));
Output:
2010-09-18
2010-09-19
I have a loop on my archive-tour page in which I output dates of on week after then the selected date.
<ul class="uol">
<?php
$start = strtotime($_GET['date']);
$dates = array();
for ($i = 0; $i <= 7; $i++) {
$date = date('Y-m-d', strtotime("+$i day", $start));
$date1 = $date;
$day = date('D', strtotime($date1));
$date = explode('-', $date);
$dateinput = date('Y-m-d', strtotime("+$i day", $start));
$date = $date[2];
echo '<li class="lia"><input type="hidden" class="getdate" value="'.$dateinput.'">' . $date . ' ' . $day . '</li>';
}
?>
<li class="lia" style="background-color:blue"><a style="background- color:blue" href="#tabs-0" class="date tdate"></a></li>
</ul>
Here i have another loop on buttons as seen below.
1:00 am - 2:00 am......
<button type="button" style="background-color:blue" id="ttime<?php echo $post->ID?>" class="btn btn-default time-pick tt_time" value=""></button>
for ($i = 0; $i <= 23; $i++) {
am = "";
if ($i <= 12) {
$am = "am";
} else {
$am = "pm";
}
echo '<button type="button" class="btn btn-default">' . $i.':00 ' . $am . ' - ' . ++$i .':00 '. $am . '</button> ';
--$i;
}
Now user can select date and according time to book tour.
i am getting the selected time and date and i want to highlight the above date and time accordingly. currently setting time and date outer then the loop. but i want to match date with selected date, if it present then highlight it and same for the time. for example in user selects 9:00 am - 10:00 am then my code add one more button with this time. i want to highlight the existing when by applying a if condition in loop that if date=selcted_date then highlight that one.
jQuery('#time<?php echo $post->ID?>').html(t_time);
$(".tdate").html(date);
how can i send the jquery variable t_time from footer page to archive page and get it on archive page in php so that i can use it in if condition.
Remember its is wordpress.
In jquery you can use localStorage.
localStorage.setItem('t_time','Your setTime' ); //set your value
And to get
localStorage.getItem('t_time'); //Get your value
Use jquery's $.post() as follows..
var ttime = jQuery('#time<?php echo $post->ID?>').html();
$.post('php_file_name.php',{'ttime':ttime},function(data,status){
});
And in your php file..
$time = $_POST['ttime'];//get ttime send from jquery
//echo $time
I want to select MySQLi records between a startdate and enddate so I have a JS script that allows me to enter dates (using HTML datebox type inputs) which I pass to a PHP script using JQuery's $.post method. My JS code is:
startDate = new Date(document.getElementById("fromDate").value);
startDate = new Date(startDate.getUTCFullYear(),startDate.getUTCMonth(), startDate.getUTCDate(), startDate.getUTCHours(), startDate.getUTCMinutes(), startDate.getUTCSeconds());
endDate = new Date(document.getElementById("toDate").value);
endDate = new Date(endDate.getUTCFullYear(), endDate.getUTCMonth(), endDate.getUTCDate(), endDate.getUTCHours(), endDate.getUTCMinutes(), endDate.getUTCSeconds());
$.post("DBQuery.php", {
startdate: startDate,
enddate: endDate,
},
function (output) {
var result = JSON.parse(output);
$('#PHPStartDate').html(result.startdate).show();
$('#PHPEndDate').html(result.enddate).show();
});
My PHP code is:
$startdate = date('Y-m-d h:i:s',strtotime($_POST["startdate"]));
$enddate = date('Y-m-d h:i:s',strtotime($_POST["enddate"]));
$con = mysqli_connect("localhost","username","password","dbase");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT * FROM Hits WHERE timestamp BETWEEN '$startdate' AND '$enddate'";
if ($result = mysqli_query($con,$sql)) {
$visitors = mysqli_num_rows($result);
}
$sql="SELECT DISTINCT session FROM Hits WHERE timestamp BETWEEN '$startdate' AND '$enddate'";
if ($result = mysqli_query($con,$sql)) {
$sessions = mysqli_num_rows($result);
}
$sql="SELECT DISTINCT country FROM Hits WHERE timestamp BETWEEN '$startdate' AND '$enddate'";
if ($result = mysqli_query($con,$sql)) {
$countries = mysqli_num_rows($result);
}
$sql="SELECT DISTINCT city FROM Hits WHERE timestamp BETWEEN '$startdate' AND '$enddate'";
if ($result = mysqli_query($con,$sql)) {
$cities = mysqli_num_rows($result);
}
$output = json_encode(array("visitors"=>$visitors,"sessions"=>$sessions,"countries"=>$countries,"cities"=>$cities,"startdate"=>$startdate,"enddate"=>$enddate));
echo $output;
mysqli_free_result($result);
mysqli_close($con);
However the dates returned by PHP are 18 hours behind the dates which JS passed to PHP - very weird! My browser and MAMP server are on the same machine (my iMac) and I live in Thailand (UTC + 7 hours).
Here's a screen shot of what is displayed in HTML using the following code:
<div id="reportTitle">
Report of site activity from
<span id="startTime"></span>on<span id="startDate"></span>to
<span id="endTime"></span>on<span id="endDate"></span><br>
for<span id="showVisitors"></span>
<span id="showCities"></span>
<span id="showCountries"></span>
</div>
<div id="reportBody">
<div>
<span><h3>From</h3></span><span id="PHPStartDate"></span>
<span><h3>to</h3></span><span id="PHPEndDate"></span>
The first set of dates displayed at the top of the screenshot are simply the JS startdate and enddatevariables and the lower set of dates are those returned by the PHP variables $startdate and $enddate which ought not to have changed (but in fact are 18 hours earlier!).
Screenshot of JS and PHP dates
I suspect the problem is to do with timezones but given that Thailand is UTC+7 it's hard to work out where the 18 hour time difference is coming from.
With this PHP-code I get the first day of the actual month
date('Y, n, 1')
The output ist
2014, 4, 1
How can I convert it to the Javascript-Date because the Javascript-Date, especially the month is zerobased. That means the output 2014, 4, 1 will be the 1st may 2014.
Try this:
<?php
$month = date("n");
$year = date("Y");
$day = 1;
?>
var myDate=new Date("<?php echo $month?> <?php echo $day?>, <?php echo $year?>");
alert(myDate);
May be this help. JS Date Demo