I need to show (today) text if date is today. How do I do that!
I tried everything but cant find the right anwser that's why Im asking here.
Here is the piece of codeI have right now.
$mod_list.= '<ul class="upcoming-events"><li>
<div class="date">
<span><span class="day">'.date($dateformat,$datetime_start).'</span>
<span><span class="month">'.date($datemonth,$datetime_start).'</span>
<span><span class="year">'.date($dateyear,$datetime_start).'</span>
</div>';
I want to show it just behind the last </span>
It is for event calendar and I want to show the text TODAY on the exact day of the event.
Any Ideas?
if(date('Y-m-d',$datetime_start)==date('Y-m-d')){
//it's today! put code here
}else{
//it's not today
}
If you don't use the second parameter in the date() function, it uses the current time. So comparing their date to today is that simple.
Ok, here is the whole Code for what I'm using, it is actualy a droplet for showing the event calendar in my sidebar.
//:Show next #N events
//:
// Get_Concerts
global $database, $wb;
setlocale (LC_ALL, 'sl_SI.UTF-8'); //za vse kategorije
setlocale (LC_TIME, 'sl_SI.UTF-8'); //za datumske funkcije
// Show how many items, defaults to 10?
if ( !isset($max) ){ $max = 10; };
// year and month and section defaults
if(!isset($year)) {$year = date('Y', time()); }
if(!isset($month)) {$month = date('n', time()); }
if(!isset($section_id)) {$section_id = 0 ; }
// Set dateformat to suit your needs, add timeformat if needed
$dateformat = 'd'; // Standard php date formats
$datemonth = 'M'; // Standard php date formats
$dateyear = 'Y'; // Standard php date formats
// Fetch base page link, if event_id = set
$extrasql = '';
$page_id = 0;
$page_link ='';
if ($section_id<>0) {
$extrasql = " section_id = '".$section_id."' AND ";
$sql = "SELECT page_id FROM ".TABLE_PREFIX."sections WHERE section_id = '".$section_id."'";
$result = $database->query($sql);
if ( $result->numRows() > 0 ) {
while( $row = $result->fetchRow() ) {
$page_id = $row['page_id'];
}
}
if ($page_id <> 0) {
$sql = "SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '".$page_id."'";
$result = $database->query($sql);
if ( $result->numRows() > 0 ) {
while( $row = $result->fetchRow() ) {
$page_link = page_link($row['link']);
}
}
}
}
// Set start- and end date for query
// $datestart = "$year-$month-1"; ORIGINAL = show all events in this month
$datestart = date("Y-m-d"); // ALTERNATIVE = show all events in this month, starting today
$dateend = "$year-$month-".cal_days_in_month(CAL_GREGORIAN, $month,$year);
$mod_list = "";
// Fetch the items
$sql = "SELECT DAY(date_start) AS day, id, custom1, date_start, time_start, date_end, time_end, name FROM ".TABLE_PREFIX."mod_procalendar_actions WHERE ".$extrasql." date_start >='$datestart' AND public_stat = 0 ORDER BY date_start,time_start LIMIT 0, ".$max." ";
$mod_query = $database->query($sql);
while ( $row =& $mod_query->fetchRow()){
// Build url like : pages/kalendar.php?id=2&detail=1
$page_url = $page_link.'?id='.$row['id'].'&detail=1';
$ds = $row['date_start']." ".substr($row['time_start'],0,5);
$de = $row['date_end']." ".substr($row['time_end'],0,5);
$datetime_start = mktime(substr($ds,11,2),substr($ds,14,2),0,substr($ds,5,2),substr($ds,8,2),substr($ds,0,4));
$datetime_end = mktime(substr($de,11,2),substr($de,14,2),0,substr($de,5,2),substr($de,8,2),substr($de,0,4));
if ($row['time_start'] !== $printTime) {
$printTime = $row['time_start'];
$mod_list.= '<ul class="upcoming-events"><li>
<div class="date"><span><span class="day">'.date($dateformat,$datetime_start).'</span><span><span class="month">'.date($datemonth,$datetime_start).'</span><span><span class="year">'.date($dateyear,$datetime_start).'</span>
</div>';
$mod_list.= '<div class="event-content"><h6>'.$row["name"].'</h6>
<ul class="event-meta"><li><i class="fa fa-clock-o"> </i>'.substr($printTime,0,5).'<sup>h</sup></li>
<!-- <li><i class="fa fa-info-circle"> </i>'.$row["custom1"].'</li> --></ul></div></li></ul>';
}
$mod_list .= "<hr>";
}
$mod_list .= 'Napovednik<br></br>';
return $mod_list;
Here is the link to the site, LINK you'll notice a TEST event which is created for today, I want a little TODAY text to be shown right beside the HOUR on the right.
I hope this helps more, Thank you
R.
Related
I have a PHP function which inserts a date value from my SQL database into my PHP page here
$DateSql = "SELECT * FROM `ins_schedule` WHERE `active` = 1";
$DateResult = mysqli_query($connect, $DateSql);
$DateResultCheck = mysqli_num_rows($DateResult);
if ($DateResultCheck > 0){
while($row = mysqli_fetch_assoc($DateResult)){
echo "<p style=\"margin-left: 15px;\">{$row[('insider_date')]}</p>";
}
}
This method works fine for printing out the date like this
2020-01-31
But I want the date data to print out as "January 31, 2020". Would anyone know how to output the data like this?
There's a couple ways to do date formatting in PHP. Here I use the DateTime::format() method:
$DateSql = "SELECT * FROM `ins_schedule` WHERE `active` = 1";
$DateResult = mysqli_query($connect, $DateSql);
$DateResultCheck = mysqli_num_rows($DateResult);
if ( $DateResultCheck > 0 ) {
while ( $row = mysqli_fetch_assoc($DateResult) ) {
$date = new DateTime( $row['insider_date'] );
echo '<p style="margin-left: 15px;">' . $date->format('F j, Y') . '</p>';
}
}
I have a small PHP page which takes data from MySQL and displays it via PHP in a monthly calendar. I'm having trouble arranging the data properly within an array to get the desired output.
First, I will describe what I would like to happen:
students come to classes on regular days of the week
they can also make or cancel reservations
the calendar also displays days when the school is not open
In order to display this data on the calendar, I use MySQL to output data from a variety of sources, and then input that into an array with PHP, which I sort by date and output.
My issue is, I would like to be able to handle more than one row of data per day, but because I am using the date as the key, I am limited on only displaying one result per day. If I use a loop to append the date with a counter in the key, I get overlapping results in situations where someone made a reservation and then cancelled that reservation on the same day.
As for my code...
First, I check to see if the student is registered in a weekly class, then input that class into the array.
$sql = "SELECT StudentDB.studentid, ClassDB.classID, ClassDB.class_level, ClassDB.class_title, ClassDB.time, ClassDB.teacher, StudentDB.first_name, StudentDB.last_name, StudentDB.payment_amount, ClassDB.day
FROM ClassDB
INNER JOIN RegDB ON ClassDB.classID = RegDB.classid
INNER JOIN StudentDB ON StudentDB.studentID = RegDB.studentid
WHERE StudentDB.studentid = '$studentid'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) { // DISPLAY REGULAR CLASS DATA
$dayofclass = $row['day'];
$class_level = $row['class_level'];
$class_title = $row["class_title"];
$day = $row["day"];
$class_time = $row["class_time"];
$time = $row["time"];
// check which dates match the days of the week and store in an array
for ($i=1;$i<=$n;$i++){
if ($i<10) {
$i = "0" . $i;
}
$day=date("l",strtotime($yearmonth.$i)); //find weekdays
if($day==$dayofclass){
$time = date("H:i",strtotime($row['time']));
$dates[]=$yearmonth.$i;
$datesdata[$yearmonth.$i] = "0";
$timedata[$yearmonth.$i] = $time;
$classiddate[$yearmonth.$i] = $row['classID'];
}
}
}
echo "</table>";
$conn->close();
}
After that, I check for specific reservations (cancelations, irregular reservations, waitlists) and input them into the array:
$lowerlimit = $yearmonth . "01";
$upperlimit = $yearmonth . "31";
$sql = "SELECT AttendanceDB.*, ClassDB.*
FROM StudentDB
INNER JOIN AttendanceDB ON StudentDB.studentid = AttendanceDB.studentid
INNER JOIN ClassDB ON AttendanceDB.classid = ClassDB.classID
WHERE StudentDB.studentid = '$studentid'
AND AttendanceDB.class_time >= '$lowerlimit'
AND AttendanceDB.class_time <= '$upperlimit'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$loopcount = 0;
// store furikae data in the array
while($row = $result->fetch_assoc()) {
$phpdate = strtotime( $row["class_time"] );
$time = date("H:i",strtotime($row['time']));
$mysqldate = date( 'Y-m-d', $phpdate );
$loopcount++;
$mysqldate = $mysqldate . "+" . $loopcount;
// $loopcount++;
// $mysqldate = $mysqldate . "+" . $loopcount;
$previousdate = $mysqldate;
$previousfurikae = $row['furikae'];
if ($row["furikae"] == 3){
$dates[]=$mysqldate;
$datesdata[$mysqldate] = "1";
$timedata[$mysqldate] = $time;
$classiddate[$mysqldate] = $row['classID'];
} elseif ($row["furikae"] == 8 OR $row["furikae"] == 7) {
$dates[]=$mysqldate;
$datesdata[$mysqldate] = "3";
$timedata[$mysqldate] = $time;
} elseif ($row["furikae"] == 2) {
$dates[]=$mysqldate;
$datesdata[$mysqldate] = "2";
$timedata[$mysqldate] = $time;
}
}
}
$conn->close();
Then finally I check the school calendar and input the days off into the array:
$sql = "SELECT *
FROM SchoolScheduleDB
WHERE date >= '$lowerlimit'
AND date <= '$upperlimit'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// store furikae data in the array
while($row = $result->fetch_assoc()) {
$phpdate = strtotime( $row["date"] );
// $time = date("H:i",strtotime($row['time']));
// $mysqldate = date( 'Y-m-d', $phpdate ) . " " . $time;
$mysqldate = date( 'Y-m-d', $phpdate );
$dates[]=$mysqldate;
$datesdata[$mysqldate] = "666";
}
}
$conn->close();
The way I intended it to work was that:
First the regular classes would be input
Then any reservations would overwrite the original plans
And finally the school calendar would overwrite everything
Currently, this functions as it should, but it is limited to displaying 1 result per day, but I would like to be able to display more than 1 result per day for students who come to multiple classes.
Thank you for your help. If I made any mistakes in my question or my question is unclear I will do my best to revise it.
You can make a Sub-Array for each date by using edged brackets:
$data[20180528][] = 'aa';
$data[20180528][] = 'bb';
$data[20180529][] = 'cc';
$data[20180529][] = 'dd';
$data[20180529][] = 'ee';
will give you an Array like this:
20180528 => aa
=> bb
20180529 => cc
=> dd
=> ee
I need help on this..
I am new in php and dummy..
$displaydate = "";
$paydate1 = "23-10-2016";
$paydate2 = "23-11-2016";
$paydate3 = "23-12-2016";
$paydate4 = "23-01-2017";
$paydate5 = "23-02-2017";
$paydate6 = "23-03-2017";
if todaydate is 23-10-2016 then $displaydate = "$paydate2" until 22-11-2016. When 23-11-2016 then $displaydate = "$paydate3" and so on.
then results
if the date is 23-10-2016 until 22-11-2016 $displaydate = "$paydate2"
if the date is 23-11-2016 until 22-12-2016 $displaydate = "$paydate3"
if the date is 23-12-2016 until 22-01-2016 $displaydate = "$paydate4"
if the date is 23-01-2016 until 22-02-2016 $displaydate = "$paydate5"
if the date is 23-02-2016 until 22-03-2016 $displaydate = "$paydate6"
please help with the code...
Thanks..
IM php DUMMY
Organize your data convenient so you can easy access it.
Put your paydates it an array:
$paydate = ["23-10-2016","23-11-2016","23-12-2016","23-01-2017","23-02-2017","23-03-2017"];
UPDATED per your comment:
$payout1 = $this->data->paymentdate1;
$payout2 = $this->data->paymentdate2;
$payout3 = $this->data->paymentdate3;
$payout4 = $this->data->paymentdate4;
$payout5 = $this->data->paymentdate5;
$payout6 = $this->data->paymentdate6;
$paydate = [$payout1,$payout2,$payout3,$payout4,$payout5,$payout6];
Transform the dates in an easy to sort format:
function trf_date($date)
{
return date('Y-m-d', strtotime($date));
}
$paydate = array_map("trf_date", $paydate );
Sort the array to be sure we will get the dates in ascending order while looping.
sort($paydate);
Now loop through the array to find the first date higher then today:
foreach($paydate as $key=>$val){
if($val > date('Y-m-d'))
break;
}
$displaydate = ''; //initialize the output variable
//check to see if the last retrieved date meets the condition not to be in the past.
//this is for the case all dates in the array are in the past
if(isset($paydate[$key]) && $paydate[$key] > date('Y-m-d'))
$displaydate = $paydate[$key];
I want to make an advertisment manager. When an ad reaches its expiry date it becomes non-active. But when I tried to make it and tried it, all of the ads change into non-active even though they haven't reached their expiry dates.
Here's my code:
$query_banner = mysql_query("SELECT * FROM ad_tbl ORDER BY ID DESC LIMIT $from,$max_show") or die(mysql_error());
while($show=mysql_fetch_array($query_banner))
{
$no++;
if(($no%2)==0)
$color = '#f2f2f2';
else
$color = '#f9f9f9';
$expired_date = $show['expiry_date'];
$today_date = date("m/d/Y");
$expired = strtotime($expiry_date);
$today = strtotime($today_date);
if($expired > $today)
{
$valid = "yes";
}
else
{
$valid = "no";
$query_expired = mysql_query("UPDATE ad_tbl SET status='Non-Active' WHERE expiry_date <= $today") or die(mysql_error());
}
}
Try:
$expiredDateTime = new DateTime($expiry_date);
$expired = $expiredDateTime->format('U');
$today = date('U'); // This will default give you timestamp for "now", saving you a step
If that works then I fear your m/d/y format could be the root of the issue. To check you should echo your strtotime values out and stick them into a converter, see what it says.
Good morning,
I am trying to alter the output of a calendar WordPress plugin for a website. I need to be able to group items by month. Ideally, I would have the month and year and below that would be a list of all the objects from that month. I have everything good to go except for the grouping by month and year.
The table is structured like this:
id | event_start | event_end | event_title | event_desc
2 | 1309935600 | 309939200 | test | Donec iaculis...
I'm new to PHP and MySQL but here's the code that is currently using (I did not write this, I've modified it for my own use -- most html / css removed):
// Add the shortcode for displaying the event on pages
function displayevents( $atts ) {
global $wpdb;
setlocale(LC_ALL, get_locale());
$table_name = $wpdb->prefix . "simple_events";
// VARIATIONS: EXPIRED / ALL / UPCOMING
if($atts['age']) {
$age = $atts['age'];
if($age == "expired") {
$range = "event_end <= " . time();
} elseif($age == "all") {
$range = "event_end > 946706400"; // timestamp for jan 1st 2000 - assuming no event will be creted before that date
} else {
$range = "event end > " . time();
}
}
if($atts['label']) $label = strtolower($atts['label']);
if($atts['limit'] > 0) { $limit = "LIMIT 0, " . $atts['limit']; } else { $limit = ""; }
if( $age && $label ) {
$allevents = $wpdb->get_results(" SELECT * FROM $table_name WHERE event_label = '$label' AND $range ORDER BY event_start $limit", "ARRAY_A");
} elseif($age) {
$allevents = $wpdb->get_results(" SELECT * FROM $table_name WHERE $range ORDER BY event_start $limit", "ARRAY_A");
} elseif($label) {
$currentTime = time();
$allevents = $wpdb->get_results(" SELECT * FROM $table_name WHERE event_label = '$label' AND event_end >= $currentTime ORDER BY event_start $limit", "ARRAY_A");
} else {
$currentTime = time();
$allevents = $wpdb->get_results(" SELECT * FROM $table_name WHERE event_end >= $currentTime ORDER BY event_start $limit", "ARRAY_A");
}
foreach ($allevents as $event) {
// decide if the year needs to be mentioned
if(date('Y',$event['event_start']) == date('Y',time())) {
$eventtime = strftime( __('%l:%M',SE_TEXTDOMAIN),$event['event_start']);
} else {
$eventtime = strftime( __('%l:%M',SE_TEXTDOMAIN),$event['event_start']);
}
$the_events[] =
strftime( __('%d',SE_TEXTDOMAIN),$event['event_end']).
stripslashes($event['event_title']).
stripslashes($event['event_desc']).
$eventtime.
' to '.
strftime( __('%l:%M',SE_TEXTDOMAIN),$event['event_end']).
$evt_loc.
$evt_url;
} // end foreach ($allevents as $event)
$items = implode($the_events);
return($items);
}
Any help would be greatly appreciated. The current output can be seen here: http://nwtechanddesign.com/jariccodance/calendar/
The desired output (styling apart) can be seen here: http://nwtechanddesign.com/wp-content/blogs.dir/11/calendar.jpg
TIA
I'm not 100% sure what you're doing with that string that you're getting back out, so I can't really
answer in a way that you'll just be able to drop in, but, given that you're creating some big string
from imploding arrays, I guess you just want to know how to drop a header in, at the right places.
Assuming your array is sorted right, which based on the queries, it looks like it should be coming
out in order, you could do something like:
$curMonth = "";
$curYear = "";
foreach($allEvents as $event)
{
// If we encounter a new month or year, change our curMonth/curYear values
// and output a new header.
if ((date('Y',$event['event_start']) != $curYear) || (date('M',$event['event_start']) != $curMonth))
{
$curMonth = date('M',$event['event_start']);
$curYear = date('Y',$event['event_start']);
// Outputs in 'Jan.2011' style
// You'll just have to deal with this somehow, like you deal with the rest of the stuff
$eventString = $curMonth.".".$curYear;
}
else
$eventString = "";
// Then instead of:
// $the_events[] =
// use
$eventString .=
... rest of your code ...
$the_events[] = $eventString;
}