Bootstrap year calendar offset events - javascript

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;
?>
]
});
});

Related

Set date from PHP variable to daterangepicker

I am trying to set date from PHP variable (because values are coming from the database) to daterangepicker but it's not working and it's setting the today's date
Code
<?php $start_date = "04-07-2021"; ?>
<?php $end_date = "10-07-2021"; ?>
<input type="text" name="date-range">
<script>
$(document).ready(function() {
var start_date = <?php echo $start_date; ?>;
var end_date = <?php echo $end_date; ?>;
$('input[name="date-range"]').daterangepicker({
startDate: start_date,
endDate: end_date,
locale: {
format: 'DD-MM-YYYY'
}
});
});
</script>
Your dates are strings so you need to put them in quotes when you turn them into JS string literals:
var start_date = "<?php echo $start_date; ?>";
var end_date = "<?php echo $end_date; ?>";
If you don't, they'll be incomprehensible to the JS interpreter and cause a syntax error (which should have been visible in your browser's Console, although you didn't mention it).

How to print fullcalendar with given date range including all events?

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>

can you manage how to add a day in a date in php?

<?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

Convert PHP-Date in Javascript-Date

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

How to loop through an array and a date range?

Here's what I need to have happen:
I have created variables that include the dates for the current week.
I have also created an array that has the sport types in it as $k => $v.
I created a javascript accordion that will open and close if clicked on. The dates of the week are used as the title of the accordion. I want to then return all the records, in their respective accordion, based on the date in the database but I also need to list those records according to sport type. So for example:
Accordion * October 2, 2013 * Accordion (when user clicks it will open and show all the records that have a game on that date listed under the sport type).
I need to echo the value of the sport type array I created if the record matches the key for the sport type. For example: if the database returns three rows of data, one having the sport type of "baseball" and two having the sport type of "MSoccer" then I need to return the records like this in a table:
BASEBALL (sport type)
VI vs. UVA close td at 6:00 PM EST
MEN'S SOCCER
VI # Montreat at 3:30 PM EST
VI vs. St. Andrews at 4:00 PM EST
if there are no records that have a game on the date then I would just echo "no games today"
Then I need to create the next accordion item and return the records for that one where the game date matches the date for the accordion.
Here's what I have so far...just not sure where to go with it:
<?php
date_default_timezone_set('US/Eastern');
$today = time();
$weekMonDate = date('Y-m-d',strtotime("last Monday", $today));
$weekTuesDate = date('Y-m-d', strtotime('+1 days', strtotime($weekStartDate)));
$weekWedDate = date('Y-m-d', strtotime('+2 days', strtotime($weekStartDate)));
$weekThursDate = date('Y-m-d', strtotime('+3 days', strtotime($weekStartDate)));
$weekFriDate = date('Y-m-d', strtotime('+4 days', strtotime($weekStartDate)));
$weekSatDate = date('Y-m-d', strtotime('+5 days', strtotime($weekStartDate)));
$weekSunDate = date('Y-m-d', strtotime('+6 days', strtotime($weekStartDate)));
$sport = array(
"Baseball" => 'BASEBALL',
"MSoccer" => 'MEN\'S SOCCER',
"MBasketball" => 'MEN\'S BASKETBALL',
);
foreach ($sport as $k => $v) {
$sql = 'SELECT gametime, conference, scrimmage, exhibition, gamedate, homeschool, visitorschool, homelivestatsurl, notes, gamestatus, homescore, visitorscore, score, record, sporttype FROM schedule WHERE WEEKOFYEAR(gamedate)=WEEKOFYEAR(NOW()) ORDER BY gamedate';
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
?>
<?php
mysql_data_seek($result, 0);
$day = ' ';
$sport = ' ';
while ($row = mysql_fetch_assoc($result)) {
if (date("d", strtotime($row['gamedate'])) !== $day) {
$day=date("d", strtotime($row['gamedate'])); ?>
?>

Categories

Resources