PHP - Calendar Date Array
Hey everyone!
I found a script on the net to display a calendar on my page and it works fine. It has a piece of code where I can specify which dates must be highlighted in a month. It looks like this: Code: [Select] $calendar->highlighted_dates = array( '2011-12-03', '2011-12-14', '2011-12-25' ); I've got a list of dates in a table in my database that I need to get into this array. It's formatted the same as in the example. Can someone please help? Thanks, Karen Similar TutorialsHey guys,
Ive been working on this script and I cant seem to figure out how to highlite the current date in lets say a blue color.
Any ideas please?
<!DOCTYPE html> <html> <head> <title>Simple Month Calendar</title> <script type="text/javascript"> // Author: Danny van der ven // Created: 12 aug 2014 // P.S. I'm from The Netherlands, so the names of the weeks and months are in Dutch. var Calendar = function(divId) { //Store div id this.divId = divId; // Days of week, starting on Sunday this.DaysOfWeek = [ 'Z', 'M', 'D', 'W', 'D', 'V', 'Z' ]; // Months, stating on January this.Months = ['januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december' ]; // Set the current month, year var d = new Date(); this.CurrentMonth = d.getMonth(); this.CurrentYear = d.getFullYear(); }; // Goes to next month Calendar.prototype.nextMonth = function() { if ( this.CurrentMonth == 11 ) { this.CurrentMonth = 0; this.CurrentYear = this.CurrentYear + 1; } else { this.CurrentMonth = this.CurrentMonth + 1; } this.showCurrent(); }; // Goes to previous month Calendar.prototype.previousMonth = function() { if ( this.CurrentMonth == 0 ) { this.CurrentMonth = 11; this.CurrentYear = this.CurrentYear - 1; } else { this.CurrentMonth = this.CurrentMonth - 1; } this.showCurrent(); }; // Show current month Calendar.prototype.showCurrent = function() { this.showMonth(this.CurrentYear, this.CurrentMonth); }; // Show month (year, month) Calendar.prototype.showMonth = function(y, m) { var d = new Date() // First day of the week in the selected month , firstDayOfMonth = new Date(y, m, 1).getDay() // Last day of the selected month , lastDateOfMonth = new Date(y, m+1, 0).getDate() // Last day of the previous month , lastDayOfLastMonth = m == 0 ? new Date(y-1, 11, 0).getDate() : new Date(y, m, 0).getDate(); var html = '<table>'; // Write selected month and year html += '<tr><td colspan="7">' + this.Months[m] + ' - ' + y + '</td></tr>'; // Write the header of the days of the week html += '<tr>'; for(var i=0; i < this.DaysOfWeek.length;i++) { html += '<td>' + this.DaysOfWeek[i] + '</td>'; } html += '</tr>'; // Write the days var i=1; do { var dow = new Date(y, m, i).getDay(); // If Sunday, start new row if ( dow == 0 ) { html += '<tr>'; } // If not Sunday but first day of the month // it will write the last days from the previous month else if ( i == 1 ) { html += '<tr>'; var k = lastDayOfLastMonth - firstDayOfMonth+1; for(var j=0; j < firstDayOfMonth; j++) { html += '<td class="not-current">' + k + '</td>'; k++; } } // Write the current day in the loop html += '<td>' + i + '</td>'; // If Saturday, closes the row if ( dow == 6 ) { html += '</tr>'; } // If not Saturday, but last day of the selected month // it will write the next few days from the next month else if ( i == lastDateOfMonth ) { var k=1; for(dow; dow < 6; dow++) { html += '<td class="not-current">' + k + '</td>'; k++; } } i++; }while(i <= lastDateOfMonth); // Closes table html += '</table>'; // Write HTML to the div document.getElementById(this.divId).innerHTML = html; }; // On Load of the window window.onload = function() { // Start calendar var c = new Calendar("divCalendar"); c.showCurrent(); // Bind next and previous button clicks getId('btnNext').onclick = function() { c.nextMonth(); }; getId('btnPrev').onclick = function() { c.previousMonth(); }; } // Get element by id function getId(id) { return document.getElementById(id); } </script> <style type="text/css"> td.not-current { color: #777; } </style> </head> <body> <div id="divCalendar"> </div> <button id="btnPrev" type="button">Terug</button> <button id="btnNext" type="button">Vooruit</button> </body> </html> Hi everyone, I have a basic calendar that I am trying to change to highlight the current date. I have got the current date highlighted using an if else statement inside a while clause, however, the issue arises when I use the forward/previous links to go to a different month - the same day is highlighted on those months as well. Here is the code snippet in question (the entire code is below): while( $day_num <= $days_in_month ) { if(date('d') != $day_num) { echo "<td> $day_num </td>"; $day_num++; $day_count++; } // display today's date else { echo "<td class=\"today\"> $day_num </td>"; $day_num++; $day_count++; } My question is how do I get this calendar to display the current date, just on the current month. I assume there is something I am missing when it comes to handling the date(s) correctly, but what? Any help is appreciated. Thanks, kaiman Full code: // gets today's date $date = time () ; // puts the day, month, and year in seperate variables $day = date('d', $date) ; $month = (int) ($_GET['month'] ? $_GET['month'] : date('m')); $year = (int) ($_GET['year'] ? $_GET['year'] : date('Y')); // generate the first day of the month $first_day = mktime(0,0,0,$month, 1, $year) ; // get the month name $current_month = date('F', $first_day) ; // determine what day of the week the first day of the month falls on $day_of_week = date('D', $first_day) ; // determine blank days before start of month switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } // determine how many days are in the current month $days_in_month = cal_days_in_month(0, $month, $year) ; // determine next month $next_month_link = '<a href="?month='.($month != 12 ? $month + 1 : 1).'&year='.($month != 12 ? $year : $year + 1).'">>></a>'; // determine previous month $previous_month_link = '<a href="?month='.($month != 1 ? $month - 1 : 12).'&year='.($month != 1 ? $year : $year - 1).'"><<</a>'; // start building the table echo " <table border=0 width=294>\n"; echo " <tr>\n"; // display month and year echo " <th> $previous_month_link </th>\n"; echo " <th colspan=4> $current_month $year </th>\n"; echo " <th> $next_month_link </th>\n"; echo " </tr>\n"; // display days of week echo " <tr>\n"; echo " <td width=42>S</td>\n"; echo " <td width=42>M</td>\n"; echo " <td width=42>T</td>\n"; echo " <td width=42>W</td>\n"; echo " <td width=42>T</td>\n"; echo " <td width=42>F</td>\n"; echo " <td width=42>S</td>\n"; echo " </tr>\n"; // counts the days in the week $day_count = 1; echo " <tr>\n"; // display blank days while ( $blank > 0 ) { echo " <td></td>\n"; $blank = $blank-1; $day_count++; } // sets the first day of the month to 1 $day_num = 1; // count the days in the month and display them while( $day_num <= $days_in_month ) { if(date('d') != $day_num) { echo "<td> $day_num </td>"; $day_num++; $day_count++; } // display today's date else { echo "<td class=\"today\"> $day_num </td>"; $day_num++; $day_count++; } // make sure we start a new row every week if ($day_count > 7) { echo " </tr>\n"; echo " <tr>\n"; $day_count = 1; } } // finish calendar while ( $day_count >1 && $day_count <=7 ) { echo " <td>\n"; echo " </td>\n"; $day_count++; } echo " </tr>\n"; echo " </table>\n"; I have the week date range displaying the week range from sunday - saturday
$current_dayname = date("0"); // return sunday monday tuesday etc. echo $date = date("Y-m-d",strtotime('last sunday')).'to'.date("Y-m-d",strtotime("next saturday")); Which outputs in the following format 2015-01-25to2015-01-31 However, when I press next or previous, the dates don't change. <?php $year = (isset($_GET['year'])) ? $_GET['year'] : date("Y"); $week = (isset($_GET['week'])) ? $_GET['week'] : date('W'); if($week > 52) { $year++; $week = 1; } elseif($week < 1) { $year--; $week = 52; } ?> <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week == 52 ? 1 : 1 + $week).'&year='.($week == 52 ? 1 + $year : $year); ?>">Next Week</a> <!--Next week--> <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week == 1 ? 52 : $week -1).'&year='.($week == 1 ? $year - 1 : $year); ?>">Pre Week</a> <!--Previous week--> <table border="1px"> <tr> <td>user</td> <?php if($week < 10) { $week = '0'. $week; } for($day= 1; $day <= 7; $day++) { $d = strtotime($year ."W". $week . $day); echo "<td>". date('l', $d) ."<br>". date('d M', $d) ."</td>"; } ?> </tr> </table> Hi all, I've been trying to find a simple script that can output an array of months within a given year which each contain the days for that month. Something along the lines of this: Code: [Select] [1] => Array ( [0] => Array ( [num] => 1 [ts] => 2011/08/01 ) .... 1 being the month (jan) 0 is the day (which contains the day & full date) Does anybody know of a script that does something along these lines as all the ones i have found seem over compliated and are outputting into tables whereas i only need this as an array? Thanks! Hello, I'm very disapointed because I don't know how do it this. I'm explain. I have a database with one input date_arrival and second date_departure. Two dates are saved in SQL format : 2014-03-02. After my SQL request to select all dates in database I'd like to add dates between date_arrival and date_departure and for each line. For example I have date_arrival date_departure line 1 : 2014-02-01 2014-02-05 line 2 : 2014-02-10 2014-02-15 In fact at the end, I have to send the result like this (with JSON) : ["2014-02-01","2014-02-02","2014-02-03","2014-02-04","2014-02-05","2014-02-10","2014-02-11","2014-02-12","2014-02-13","2014-02-14","2014-02-15"] Can you give me some help to add intermediates values in an array ? Thx Hi Everyone I have an older coded side that I am looking at for a friend, I need to add in a date diff colum into their existing index page. I can add using the following code onto the indivudually record page can't get it to work on the index. Any help is appreciated. Code on Individual page which works::: <HEAD> <? if($test['settlement_date']=="0000-00-00"){ $date1 = new DateTime($date_received); $date2 = new DateTime("now"); $interval = $date1->diff($date2); } else { $date1 = new DateTime($date_received); $date2 = new DateTime($settlement_date); $interval = $date1->diff($date2); } ?> </HEAD> <Body> <?php echo "".$interval->days."";?> </BODY> I was trying to add something similar but as it is a list I can't work out what I need to do. INDEX::: while($test = mysql_fetch_array($result)) { $complaint_id = $test['complaint_id']; echo"<tr>"; echo"<td class='standard_left'>".$test['complaint_id']."</td>"; echo"<td class='standard_left'>".$test['status']."</td>"; echo"<td class='standard_left'>".$test['LastName'].", ".$test['FirstName']."</td>"; echo"<td class='standard_left'><a href ='complaint_view.php?complaint_id=$complaint_id'>".$test['complainant']."</td>"; echo"<td class='standard_center'>".$test['date_received']."</td>"; echo"<td class='standard_center'>".$test['settlement_date']."</td>"; echo"<td class='standard_center'>".$test['interval->days']."</td>"; echo "</tr>"; I know it is old redundent code but if I can get this one colum working I would be happy. Hi,
i have an issue to sort gallery photos by date. Right now its sort by Value (Name).
here is the code
index.php contains :
<div> <?php foreach($categories_array as $photo_category=>$photos_array){?> <?php $category_thumbnail = $gallery_url."/layout/pixel.gif"; if(file_exists('files/'.$photo_category.'/thumbnail.jpg')){ $category_thumbnail = $gallery_url.'/'.$photo_category.'/thumbnail.jpg'; } $category_url = $gallery_url.'/'.$photo_category; ?> <span class="category_thumbnail_span" style="width:<?php echo $settings_thumbnail_width;?>px; height:<?php echo $settings_thumbnail_height+20;?>px;"> <a class="category_thumbnail_image" href="<?php echo $category_url;?>" style="width:<?php echo $settings_thumbnail_width;?>px; height:<?php echo $settings_thumbnail_height;?>px; background-image:url('<?php echo $gallery_url;?>/layout/lens_48x48.png');" title="<?php echo htmlentities(ucwords(str_replace('-', ' ', $photo_category)));?>"> <img src="<?php echo $category_thumbnail;?>" width="<?php echo $settings_thumbnail_width;?>" height="<?php echo $settings_thumbnail_height;?>" alt="<?php echo htmlentities(ucwords(str_replace('-', ' ', $photo_category)));?>" /> </a> <a class="category_thumbnail_title" href="<?php echo $category_url;?>" title="<?php echo htmlentities(ucwords(str_replace('-', ' ', $photo_category)));?>"> <?php echo htmlentities(str_replace('-',' ', truncate_by_letters($photo_category, 16, '..')), ENT_QUOTES, "UTF-8");?> (<?php echo count($photos_array);?>) </a> </span> <?php } ?> </div>the sort function : ksort($categories_array); So i've got a CSV file, pull data from it and it's stored within an array. $data[0] contains date that looks like so 9/14/2011 00:00:00. How can i sort this array before displaying it so that it's sorted by Date ASC by default. Code: [Select] <?php if (($handle = fopen("http://www.website.com/images/uploads/Recruitment_for_Web.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) { echo '<tr>'; echo '<td>' . str_replace("0:00:00","",$data[0]) . '</td>'; echo '<td>' . $data[1] . '</td>'; echo '<td>' . $data[2] . '</td>'; echo '<td>' . $data[3] . '</td>'; echo '<td>' . $data[4] . '</td>'; echo '<td>'; if($data[7] != "") { echo '<a href="' . $data[7] . '" target="_blank">' . $data[5] . '</a>'; } else { echo $data[5]; } echo '</td>'; echo '<td>' . $data[6] . '</td>'; echo '</tr>'; } fclose($handle); } ?> Thanks Hi, all! I've got a text field in my DB, and inside it i have several date formmated like "02/02/2001". I need to find, from all the found dates, which one is the newest. I thought using regex 'd be nice, am i right? Googlin, i've found http://www.roscripts.com/PHP_regular_expressions_examples-136.html, which lead me using something like: Code: [Select] function do_reg($text, $regex) { preg_match_all($regex, $text, $result, PREG_PATTERN_ORDER); for ($i = 0; $i < count($result[0]); $i++) { $result[0][$i]; } } But the given expressions are for cheking if there is any invalid date: Code: [Select] //Date yyyy-mm-dd //1900-01-01 through 2099-12-31 //Matches invalid dates such as February 31st '(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])' So, anyone? P.s.: this is because i'm importing a full-messed 'DB'. Thanks! Hello, I'm making a imagegallery and when someone upload a new image that image has to appear as first picture of the gallery. I'm using an array for the files, but how can I sort the files on date, newest first.? <?php $n = 0; $pathToThumbs = "images/tekeningen/"; $dir = opendir( $pathToThumbs ); while (false !== ($fname = readdir($dir))){ // strip the . and .. entries out if ($fname != '.' && $fname != '..'){ $tekeningen[$n] = $fname; } echo $tekeningen[$n]."<br />"; $n = $n +1; } closedir( $dir ); ?> I found solutions with ksort and filemtime, but I don't understand them and/or they didn't work for me. I'm going crazy. I have two arrays. The first has working hours and the array is like this: ```array(7) { [0]=> array(4) { ["morning_from"]=> string(6) "closed" ["morning_to"]=> string(6) "closed" ["afternoon_from"]=> string(5) "13:00" ["afternoon_to"]=> string(5) "19:00" }``` The second one is the busy times, the array is like this: ```array(2) { [0]=> { ["title"]=> string(13) "Test" ["start_date"]=> string(19) "2019-11-25 13:00:00" ["end_date"]=> string(19) "2019-11-25 14:00:00" } }```
Now I do a cycle of 15 times because I need to make the list for the next 15 days from today.
``` Unfortunately it does not work as I would like, it does not mark correctly if the date is occupied. I'll post a piece of code:
if($book_i == 0){
$book_day = ucwords(strftime('%d %h', strtotime($book_today_day)));
if(count($getListCalendarStartToday) > $count_list_calendar_p){
$count_more_appointment_on_some_days_morning = 0;
foreach ($getListCalendarStartToday as $key => $value) {
if($day == $book_today_day){ $book_output .= "<li>"; if(isset($user["working_time"]) && $user["working_time"]){ $book_output .= "<div><p>".$book_name_day."</p><p>".$book_day."</p></div>";
if($book_name_day == $lang["days-mon"]){
$book_morning_from = $book_array_working_time[$book_day_int]["morning_from"];
$book_morning_from_hour = (int)substr($book_morning_from, 0, 2);
$book_afternoon_from_hour = (int)substr($book_afternoon_from, 0, 2);
$book_morning_from_hour_duplicated = $book_morning_from_hour;
$book_afternoon_from_hour_duplicated = $book_afternoon_from_hour;
$book_check_closed = 0;
if($book_afternoon_from_hour == 0 && $book_afternoon_to_hour == 0){ $book_output .= "<div>";
for ($n=0; $n < $count_more_appointment_on_some_days_afternoon; $n++) {
$day_appointment_p_start_hour = date('H', strtotime($getListCalendarStartToday[$count_list_calendar_p]["start_date"]));
if($book_afternoon_from_hour_duplicated != $book_afternoon_from_hour){
if($book_afternoon_from_hour != $book_afternoon_to_hour){
$book_afternoon_from_hour_duplicated += 1; if($book_afternoon_from_min == 0){
if($day_appointment_p_start_hour == $day_appointment_p_end_hour){
$count_hour_appointment = 0;
$count_hour_appointment += 1;
$book_afternoon_from_hour_duplicated += $count_hour_appointment; break; }else{ if($book_i == 0){
if($day_appointment_p_start_min >= $book_afternoon_from_min && $day_appointment_p_start_min <= 30){ }else{
if($day_appointment_p_start_min >= $book_afternoon_from_min && $day_appointment_p_start_min >= 30){ }
$book_output .= "<a class='uk-button-book-a-visit-hour' id='a-book-a-visit' data-book-day='".$book_today_day."' data-book-hour='".number_add_leading_0($book_afternoon_from_hour).":00'>".number_add_leading_0($book_afternoon_from_hour).":00</a>"; }else{
$book_afternoon_from_hour_duplicated += 1;
if($book_afternoon_from_min == 0){
if($book_afternoon_from_min == $book_afternoon_to_min){
$book_output .= "</div>";
$book_output .= "</li>"; Hi guys I'm kinda stuck..so hopefully you guys can lend me a hand I've got an array containing date elements ("Y-m-d")... I'm trying to output some data into googlecharts..so i need to count how many elements that are in the array with todays date -1 day, todays date-2 days...todays date -3days etc... Up until a set number of days (for example 7 days, 14 days etc).. Any advice on how to go about to achieve this? /* Output of the table will display the Suite based on the distinct date. The pass rate percentage calculate based on the Suite1 and app1 and the specific date. For example at Apr 4 2011, I need to Sum the total passcount,failcount,errorcount of Bluetooth, GPSA, EMIReceiver($app1) of XA9 on Real MXE($suite1) , then calculate the passrate percentages. But I fail to get the correct value of the passcount, failcount, errorcount value.Helps! Output of the table suite Date Percentages(pass rate) XA9 on Real MXE Apr 4 2011 9:47AM 99.94% XA9 on Real MXE Apr 5 2011 10:48AM 99.94% XA9 on Real MXE Apr 6 2011 9:49AM 99.95% XA9.5 on Real EXA_B40 Apr 4 2011 7:06AM 99.94% XA9.5 on Real EXA_B40 Apr 5 2011 7:14AM 99.93% XA9.5 on Real EXA_B40 Apr 6 2011 7:29AM 99.93% */ $suite1 --> array value (XA9 on Real MXE, XA9.5 on Real EXA_B40) $app1 --> array value (Bluetooth, GPSA, EMIReceiver) if(is_array($suite_type1)){ foreach($suite_type1 as $suite1) { $sql222="Select Distinct a.StopDTTM from Suite a,Test b where a.SuiteID=b.SuiteID and b.SuiteID=a.SuiteID and a.StopDTTM>='$fromdate' and a.StopDTTM<='$to_date' and a.SuiteFilePath like '%$Program%' and a.SuiteFileName='$suite1'"; $result222=mssql_query($sql222,$connection) or die("Failed Query of".$sql222); while($row222 = mssql_fetch_array($result222)) { $datetotest = $row222[0]; $days_to_add = 1; $tilldate = fnc_date_calc($datetotest,$days_to_add); //Query the result based on the date $sql223="Select Distinct a.SuiteFileName, a.SuiteID,a.StopDTTM from Suite a,Test b where a.SuiteID=b.SuiteID and b.SuiteID=a.SuiteID and a.StopDTTM>='$row222[0]' and a.StopDTTM<='$tilldate' and a.SuiteFilePath like'%$Program%' and a.SuiteFileName='$suite1' order by a.StopDTTM"; $result223=mssql_query($sql223,$connection) or die("Failed Query of".$sql223); while($row223 = mssql_fetch_row($result223)){ foreach($app_type1 as $app1) { $sql3="Select Sum(b.passcount),Sum(b.failcount),Sum(b.errorcount) from Suite a,Test b where a.SuiteID=b.SuiteID and b.SuiteID=a.SuiteID and a.StopDTTM>='$row222[0]' and a.StopDTTM<='$tilldate' and a.SuiteFilePath like '%$program%' and a.SuiteFileName = '$suite1' and b.Product='$app1'"; $result3=mssql_query($sql3,$connection) or die("Failed Query of ". $sql3); $row3 = mssql_fetch_row($result3); $total_passcount+=$row3[0]; $total_failcount+=$row3[1]; $total_errorcount+=$row3[2]; } $overall_total=$total_passcount+$total_failcount+$total_errorcount; echo "<tr>"; echo "<td><a href='detailsreport.php?suiteID=".$row223[1]."&suitetype=".$row223[0]."&fromdate=".$fromdate."&to_date=".$to_date."&date=".$row222[0]."&tilldate=".$tilldate."&SuiteFilePath=".$Fprogram."'>" . $row223[0] . "</a></td>"; //Suite File Name echo "<td>" . $row223[2] . "</td>"; //Pass percentage if($total_passcount>0){ echo "<td bgcolor=00FF33>" . number_format((($total_passcount/$overall_total)*100),2)."%</td>"; } else{ echo "<td bgcolor=00FF33>0%</td>"; } } } } echo "</table>"; } Hi - I am passing $_POST data from an HTML form. The POST array looks like this: Code: [Select] Array ( [location] => Array ( [0] => Collingwood [1] => Varsity ) [4] => 01 Apr 2012 [1] => 12 Apr 2012 [2] => 01 May 2012 [3] => 01 Jun 2014 [8] => 01 Jul 2012 [6] => 12 Aug 2012 [7] => 20 Apr 2013 [5] => 20 Apr 2014 [submit] => Save Changes ) I am using a foreach loop to separate the keys from the values. The $values include dates and locations. I then pass $values to strtotime to convert the dates to a Unix Time stamp. when strtotime sees the Locations - it throws a PHP error "strtotime() expects parameter 1 to be string, array given" so my question is what can I do to separate the Dates from the locations in order to avoid the error ? MANY THANKS to anyone who can give advice on this ! Hey, I'm using a script which allows you to click on a calendar to select the date to submit to the database. The date is submitted like this: 2014-02-08 Is there a really simple way to prevent rows showing if the date is in the past? Something like this: if($currentdate < 2014-02-08 || $currentdate == 2014-02-08) { } Thanks very much, Jack Hello all!
I have this array of objects:
Array ( [0] => stdClass Object ( [first_name] => test [last_name] => test [title] => test [id] => 34 [type] => 4 [manager] => 4 [email] => p@yahoo.com [date] => 2014-09-21 07:23:12 [status] => 2 [approval_date] => 2014-09-21 07:31:10 [assessment_id] => 1 [supervisor_approval] => 1 [manager_approval_date] => 2014-09-21 07:31:27 [mainmanger] => 3 ) [1] => stdClass Object ( [first_name] => test [last_name] => test [title] => test [id] => 34 [type] => 4 [manager] => 4 [email] => p@yahoo.com [date] => 2014-09-20 07:39:55 [status] => 2 [approval_date] => 2014-09-20 07:40:41 [assessment_id] => 3 [supervisor_approval] => 1 [manager_approval_date] => 2014-09-20 07:41:07 [mainmanger] => 3 ) [2] => stdClass Object ( [first_name] => jimmy john john [last_name] => john [title] => Lorad and Master [id] => 32 [type] => 4 [manager] => 3 [email] => j@j.com [date] => 2014-09-21 07:38:50 [status] => 2 [approval_date] => 2014-09-19 07:39:25 [assessment_id] => 2 [supervisor_approval] => 1 [manager_approval_date] => 2014-09-19 07:39:25 [mainmanger] => 0 ) )Where "id" = the user ID. If there are two or more entries for a user, I want to remove all but the most recent by the "approval_date",... So for the above example it would return: Array ( [0] => stdClass Object ( [first_name] => test [last_name] => test [title] => test [id] => 34 [type] => 4 [manager] => 4 [email] => piznac@yahoo.com [date] => 2014-09-21 07:23:12 [status] => 2 [approval_date] => 2014-09-21 07:31:10 [assessment_id] => 1 [supervisor_approval] => 1 [manager_approval_date] => 2014-09-21 07:31:27 [mainmanger] => 3 ) [1] => stdClass Object ( [first_name] => jimmy john john [last_name] => john [title] => Lorad and Master [id] => 32 [type] => 4 [manager] => 3 [email] => j@j.com [date] => 2014-09-21 07:38:50 [status] => 2 [approval_date] => 2014-09-19 07:39:25 [assessment_id] => 2 [supervisor_approval] => 1 [manager_approval_date] => 2014-09-19 07:39:25 [mainmanger] => 0 ) )I'm having a hard time wrapping my head around this concept, so I don't have any example code. And I don't really need or expect someone to code this for me,. just a push in the right direction would be awesome. Hello. I'm new to pHp and I would like to know how to get my $date_posted to read as March 12, 2012, instead of 2012-12-03. Here is the code: Code: [Select] <?php $sql = " SELECT id, title, date_posted, summary FROM blog_posts ORDER BY date_posted ASC LIMIT 10 "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $title = $row['title']; $date_posted = $row['date_posted']; $summary = $row['summary']; echo "<h3>$title</h3>\n"; echo "<p>$date_posted</p>\n"; echo "<p>$summary</p>\n"; echo "<p><a href=\"post.php?id=$id\" title=\"Read More\">Read More...</a></p>\n"; } ?> I have tried the date() function but it always updates with the current time & date so I'm a little confused on how I get this to work. I have tried a large number of "solutions" to this but everytime I use them I see 0000-00-00 in my date field instead of the date even though I echoed and can see that the date looks correct. Here's where I'm at: I have a drop down for the month (1-12) and date fields (1-31) as well as a text input field for the year. Using the POST array, I have combined them into the xxxx-xx-xx format that I am using in my field as a date field in mysql. <code> $date_value =$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']; echo $date_value; </code> This outputs 2012-5-7 in my test echo but 0000-00-00 in the database. I have tried unsuccessfully to use in a numberof suggested versions of: strtotime() mktime Any help would be extremely appreciated. I am aware that I need to validate this data and insure that it is a valid date. That I'm okay with. I would like some help on getting it into the database. Alright, I have a Datetime field in my database which I'm trying to store information in. Here is my code to get my Datetime, however it's returning to me the wrong date. It's returning: 1969-12-31 19:00:00 $mysqldate = date( 'Y-m-d H:i:s', $phpdate ); $phpdate = strtotime( $mysqldate ); echo $mysqldate; Is there something wrong with it? (continuing from topic title) So if I set a date of July 7 2011 into my script, hard coded in, I would like the current date to be checked against the hard coded date, and return true if the current date is within a week leading up to the hard coded date. How could I go about doing this easily? I've been researching dates in php but I can't seem to work out the best way to achieve what I'm after. Cheers Denno |