PHP - Wrong Date?
I have a MySQL column which holds the date in DATETIME format. When I pull it and try and format it in php using the DATE function the times are wrong. See code below:
<?php print date("d/m/y @ G:H:s A", strtotime($pt->transaction_date)); ?> Anyone know why this is the case ? Similar TutorialsAlright, 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? Hey All, As of this morning our gallery has started to show the incorrect dates. Please go to: http://www.nightlifeguestlist.com/c...n/74/Carbon.htm you will see the first date is Fri, 29 October 10 this should be Sat, 30 October 10. In the database the date is in putted as 2010-10-30. The dates from Fri, 29 October 10 to Fri, 2 April 10 are all incorrect. These happen to be all BST times. While the dates for GMT are OK. The clocks here in the UK are now GMT and not BST. Has this anything to do with it? The code used is as follows: <? $location = false; if(isset($_GET['l'])){ $location = $_GET['l']; } $venue = false; if(isset($_GET['v'])){ $venue = $_GET['v']; } $event = false; if(isset($_GET['e'])){ $event = $_GET['e']; } $page = 0; if(isset($_GET['p'])){ $page = $_GET['p']; $page--; } $query_events = ""; if(!$location){ $query_events = "SELECT ec_venues.location FROM ec_venues GROUP BY ec_venues.location"; } else if($location && !$venue && !$event){ $query_events = "SELECT ec_venues.venue_name, UNIX_TIMESTAMP(ec_events.event_date) AS event_date, ec_venues.venue_id, ec_events.event_id,ec_venues.location FROM ec_events INNER JOIN ec_venues ON ec_events.venue_id = ec_venues.venue_id WHERE ec_events.event_date IS NOT NULL AND ec_venues.location='".$location."' ORDER BY UNIX_TIMESTAMP(ec_events.event_date) DESC LIMIT 0,1"; } else if($venue && !$event){ $query_events = "SELECT UNIX_TIMESTAMP(ec_events.event_date) AS event_date, ec_venues.venue_name, ec_venues.venue_id, ec_events.event_id, ec_events.event_name,ec_venues.location FROM ec_events INNER JOIN ec_venues ON ec_events.venue_id = ec_venues.venue_id WHERE ec_venues.venue_id=".$venue." ORDER BY UNIX_TIMESTAMP(ec_events.event_date) DESC"; } else if($venue && $event){ $query_events = "SELECT ec_venues.venue_name, ec_events.event_name, UNIX_TIMESTAMP(ec_events.event_date) AS event_date, ec_events.image_folder, ec_venues.images_per_page,ec_venues.location FROM ec_events INNER JOIN ec_venues ON ec_events.venue_id = ec_venues.venue_id WHERE ec_events.event_id=".$event." AND ec_venues.venue_id=".$venue.""; } mysql_select_db($database_nightlife2 , $nightlife2 ); // $query_events = "SELECT ec_venues.venue_name, ec_events.event_name, UNIX_TIMESTAMP(ec_events.event_date) AS event_date, ec_events.image_folder, ec_venues.images_per_page FROM ec_events INNER JOIN ec_venues ON ec_events.venue_id = ec_venues.venue_id WHERE ec_events.event_id=".$event." AND ec_venues.venue_id=".$venue.""; //echo $query_events; $events = mysql_query($query_events, $nightlife2 ) or die(mysql_error()); $row_events = mysql_fetch_assoc($events); $totalRows_events = mysql_num_rows($events); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?=(!$location?"Elite Parties Photos":"Nightlife Guestlist @ ".$location." Club - ".$row_events['venue_name'])?></title> <link href="http://www.nightlifeguestlist.com/wp-content/themes/NLGL/style.css" rel="stylesheet" type="text/css" /> <!--[if IE 6]> <link rel="stylesheet" type="text/css" href="http://www.nightlifeguestlist.com/wp-content/themes/NLGL/IE-6.css" /> <![endif]--> <!--[if IE]> <link rel="stylesheet" type="text/css" href="http://www.nightlifeguestlist.com/wp-content/themes/NLGL/IE-8.css" /> <![endif]--> <? if($_SERVER['HTTP_HOST']=="elite"){?> <BASE HREF="http://elite/"> <? } else { ?> <BASE HREF="http://www.nightlifeguestlist.com/"> <? } ?> <SCRIPT language="JavaScript" src="/mircoFinestra.js"></script> <script src="/AC_RunActiveContent.js" type="text/javascript"></script> </style> </head> <body> <div class="wrapper"> <div id="head"> <div id="header"> </div> <!-- nav --> <div id="nav"> <div id="nav-area"> <ul> <li class='page_item current_page_item'><a href='http://www.nightlifeguestlist.com' title='Home'>Home</a></li><li class="page_item page-item-3"><a href="http://www.nightlifeguestlist.com/guest-lists" title="Guest Lists">Guest Lists</a></li> <li class="page_item page-item-5"><a href="http://www.nightlifeguestlist.com/photogallery.php" title="Photo Gallery">Photo Gallery</a></li> <li class="page_item page-item-7"><a href="http://www.nightlifeguestlist.com/video-gallery" title="Video Gallery">Video Gallery</a></li> <li class="page_item page-item-9"><a href="http://www.nightlifeguestlist.com/jobs" title="Jobs">Jobs</a></li> <li class="page_item page-item-11"><a href="http://www.nightlifeguestlist.com/membership" title="Mailing List">Mailing List</a></li> <li class="page_item page-item-16"><a href="http://www.nightlifeguestlist.com/tables" title="Tables">Tables</a></li> <li class="page_item page-item-13"><a href="http://www.nightlifeguestlist.com/event-management" title="Event Management">Event Management</a></li> <li class="page_item page-item-538"><a href="http://www.nightlifeguestlist.com/blog" title="Blog">Gossip Blog</a></li> </ul> </div> </div> <!-- end nav --> <div class="clear"></div> </div> <!--/head --> <div class="narrowcolumn"> <div class="entry"> <div id="content-area"> <!-- 1 --> <div id="section"> <? if($venue && !$event){ ?><?php $pCount = 0; $myNum = sprintf("%02d",$venue); echo "<img src='interiors/" . $myNum . "_logo.gif' vspace='2' hspace='2'>\n"; if ($handle = opendir('interiors')) { while (false !== ($file = readdir($handle))) { if (substr($file,0,6) == $myNum . "_pic") { echo '<img src="interiors/' . $file . '" vspace="2" hspace="2">'; if($pCount++ % 2 == 1) echo ""; } } closedir($handle); } ?> <? } ?> <? if(!$location){?> <!-- 2 --> <div id="section"> <? do{ $query_latest = "SELECT ec_venues.venue_name, UNIX_TIMESTAMP(ec_events.event_date) AS event_date, ec_venues.venue_id, ec_events.event_id FROM ec_events INNER JOIN ec_venues ON ec_events.venue_id = ec_venues.venue_id WHERE ((ec_events.event_date) IS NOT NULL) AND ec_venues.location='".$row_events['location']."' ORDER BY UNIX_TIMESTAMP(ec_events.event_date) DESC LIMIT 0,1"; $latest = mysql_query($query_latest, $nightlife2 ) or die(mysql_error()); $row_latest = mysql_fetch_assoc($latest); $totalRows_latest = mysql_num_rows($latest); ?> <a href="club_dates/<?=$row_events['location']?>/<?=$row_latest['venue_id']?>/<?=$row_latest['event_id']?>/<?=str_replace(" ","_",$row_latest['venue_name'])?>_page1.htm "><?=$row_events['location']?> - <?php echo date("l jS F",$row_latest['event_date']); ?> @ <?php echo $row_latest['venue_name']; ?></a><br> <? } while ($row_events = mysql_fetch_assoc($events)); mysql_free_result($latest); ?> </div> <!-- 3 --> <div id="section"> <? } else if(!$venue){ ?> </div> <!-- 4 --> <div id="section"> Our most recent event was <strong><a style="color:#000000; font-weight:bold;" href="club_dates/<?=$row_events['location']?>/<?=$row_events['venue_id']?>/<?=$row_events['event_id']?>/<?=str_replace(" ","_",$row_events['venue_name'])?>_page1.htm "><?php echo date("l jS F",$row_events['event_date']); ?> @ <?php echo $row_events['venue_name']; ?></a></strong> <? } else if($venue && !$event){?> </div> <!-- 5 --> <div id="section"> <table width="100%" border="0" align="left" cellpadding="0" cellspacing="10"> <tr> <td colspan="4"><? if($totalRows_events==0){ ?> No photos are avaliable yet for this venue. <? } else { ?> Select a Date for <?php echo $row_events['venue_name']; ?> <? } ?> </td> </tr> <? $count = 0; do { if($count % 3 == 0){ echo '<tr>'; } ?> <td width="713"><a style="color:#000000; font-weight:bold;" href="club_dates/<?=$location?>/<?=$venue?>/<?=$row_events['event_id']?>/<?=str_replace(" ","_",$row_events['venue_name'])?>_page1.htm"><? echo ($row_events['event_date']==""?$row_events['event_name']:date("D, j F y",$row_events['event_date'])); ?></a></td> <?php if($count % 3 == 2){ echo "</tr>"; } $count++; } while ($row_events = mysql_fetch_assoc($events)); echo str_repeat("<td> </td>",4-($count % 4)); ?> </table> </div> <!-- 6 --> <div id="section"> <? } else if($venue && $event){ ?> </div> <!-- 7 --> <div id="section"> <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td><? if ($dir = @opendir("photos/".$row_events['image_folder'])){ while (($file = readdir($dir)) !== false) { if(substr($file,0,4) == "page"){ $dirlist[] = $file; } } sort ($dirlist); reset ($dirlist); closedir($dir); } if ($dir = @opendir("photos/".$row_events['image_folder']."/".$dirlist[$page])){ while (false !== ($file = readdir($dir))) { if(substr($file,-3)=="jpg"){ $imglist[] = $file; } } usort($imglist,"strnatcmp"); reset ($imglist); closedir($dir); } $count = 0; $paging = ""; if($page==0){ $paging .= "<< "; } else $paging .= "<a href='/club_dates/".$location."/".$venue."/".$event."/".str_replace(" ","_",$row_events['venue_name'])."_page".($page).".htm' style='color:#000000; font-weight:bold;'><<</a> "; foreach($dirlist as $f){ if($page!=$count){ $paging .= "<a href='/club_dates/".$location."/".$venue."/".$event."/".str_replace(" ","_",$row_events['venue_name'])."_page".($count+1).".htm' style='color:#000000; font-weight:bold;'>".($count+1)."</a> "; } else { $paging .= ($count+1)." "; } $count++; } if($page==count($dirlist)-1){ $paging .= ">> "; } else $paging .= "<a href='/club_dates/".$location."/".$venue."/".$event."/".str_replace(" ","_",$row_events['venue_name'])."_page".($page+2).".htm' style='color:#000000; font-weight:bold;'>>></a>"; ?></td> </tr> <tr> <td><? echo "<table width='720'><tr><td>Nightlife Guestlist @ ".$row_events['venue_name'].($row_events['event_date']!="" ?" - ".date("l jS F Y", $row_events['event_date']) : "")." - ".$location."</td><td align='right'>".$paging."</td></tr></table>\n"; ?></td> </tr> <tr> <td><? for($count=0;$count<count($imglist);$count++){ echo "<a href='javascript:;'><img alt='".$imglist[$count]." @ ".$location." Club ".$row_events['venue_name'].", ".date("jS F Y", $row_events['event_date'])."' border='0' width='90px' height='60px' hspace='5px' vspace='5px' src='"."photos/".$row_events['image_folder']."/".$dirlist[$page]."/thumbs/".$imglist[$count]."' onclick='NewWindow(\"/popup.php?t=".count($imglist)."&n=".$count."&f=".$row_events['image_folder']."&p=".$dirlist[$page]."&title=".urlencode($location." Club ".$row_events['venue_name']." on ".date("jS F Y", $row_events['event_date']))."\",\"name\",\"600\",\"420\",\"no\");return false;'></a>\n"; if($count % 7 == 6){ echo "<br>\n"; } } ?> <? } ?></td> </tr> <tr> <td> </td> </tr> </table> </div> <div id="section"> <? if(!$location){ ?> <? } else { include("getClubLogos.php"); } ?> (Sorry for the amount of code!) I use the same code for another site on another server and it works fine. I guess I need to alter the code somehow? The gallery works ok just the dates show are wrong. Any ideas on how to fix this? The server settings/time seems are OK. The line which prints the date is:<? echo ($row_events['event_date']==""?$row_events['event_name']:date ("D, j F y", $row_events['event_date'])) ; ?> When I echo the date echo date('c'); I receive 2010-10-29T23:00:00+00:00 for Fri, 29 October 10. Thanks Hi, when i try to insert to table date value it gives me wrong current date. $joindate = date('m-d-Y'); $sql = mysqli_query($con,"INSERT INTO staff (OracleID,StaffName,Des,joindate,username,password,isadmin) VALUES ('$oracleid','$name','$des','$joindate','$username', '$pass','$isadmin')"); i get this in the main page after making date("d-m-Y",strtotime(date)) 30-11--0001 why is that? Edited April 7, 2020 by ramiwahdanI'm practising how to do date and time in PHP. I wanted to see if I can get all of the date/time variables from user submission and format them correctly. I went with ISO 8601 date... // From the Manual: // date('c', mktime(1, 2, 3, 4, 5, 2006)); // Prints something like: 2006-04-05T01:02:03+00:00 ...but my attempts always produce a slightly different result for the year, month and timezone... Code: [Select] $inputTime = date('c', mktime((int)$timeHour, (int)$timeMins, (int)$timezone, (int)$dateMonth, (int)$dateDay, (int)$dateYear)); echo $inputTime; // Should return: 2013-11-02T02:30:01+00:00 // Instead returns: 2012-12-02T02:30:01-08:00 The timezone value coming from HTML... <option value="1.0">(GMT +1:00)</option> I noticed; 1. It always picks a year less than whatever year I select. 2. It always selects 12 as the month. 3. It always adds -08:00 after the picking the correct timezone. How come? Thanks in advance. I think it is unusual but i dont know to fix it. when my computer clock shows 16: 13 hours , date() reuturns 10:43:16 . My systems time zone is +5.30 GMT. how does date() subtracts 5.30 hrs from the system time? First, I would like to say when i tried to recover my account from this website, I took me 10 attempts to get the captcha right and then finally it said it sent me an email to my gmail account. I checked spam folder and everything there was no such email from this site. Then I decided to create a new account, well, it took me another 10 attempts to get the captcha right and finally when it was submitted, the page was loading for around 3 minutes before it signed me in.
My question is about the php date() function. It accepts a format to display a time. In the following example I use F for full representation of month, d for 2-digit day of month with leading zeros, Y for full year, g for 12-hour format without leading 0s, s for seconds and A for meridiem. It uses the correct format, but it gives me the wrong time. My local time is 4:43 and it prints out 4:12:
<?php echo "<p>order processed on " . date("F d, Y g:sA") . "</p>"; ?> Why is it 30 minutes behind?
Question:
Background:
Example: The Pacific ("Los Angeles") time right now is 7:58pm, but my code says it's 6:58pm. So now I have to go in and correct the "PT8H" portion. I'm wondering if there is some code I can use whereby I can simply "set it and forget it." Thank you! Edited May 2, 2020 by StevenOliverHey, 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 I am querying... $sql = "SELECT `messages_inbox`.`message_id`, `users`.`firstname`, `users`.`lastname`, `users`.`username` AS `from`, '${user_info['username']}' AS `to`, `subject`, LENGTH(`files`) AS `len`, 'inbox' AS `box`, DATE_FORMAT(`messages_inbox`.`time` ,'%T %D-%M-%Y') AS `time` "; $sql .= "FROM `messages_inbox` INNER JOIN `users` ON `messages_inbox`.`from_id` = `users`.`id` WHERE `to_id` = ${user_info['uid']} AND `messages_inbox`.`deleted` = 0 ORDER BY `messages_inbox`.`message_id` DESC"; and I am trying to output $displayName = ucwords("${message['firstname']} ${message['lastname']}"); by using $messages = pm_fetch_all($_GET['box']); I know my fetch works but for some reason firstname and lastname are only returning the logged in users first name and last name, not the person who sent the message. 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. Hi, I have a job listing website which displays the closing date of applications using: $expired_date (This displays a date such as 31st December 2019) I am trying to show a countdown/number of days left until the closing date. I have put this together, but I can't get it to show the number of days. <?php $expired_date = get_post_meta( $post->ID, '_job_expires', true ); $hide_expiration = get_post_meta( $post->ID, '_hide_expiration', true ); if(empty($hide_expiration )) { if(!empty($expired_date)) { ?> <span><?php echo date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( $post->ID, '_job_expires', true ) ) ) ?></span> <?php $datetime1 = new DateTime($expired_date); $datetime2 = date('d'); $interval = $datetime1->diff($datetime2); echo $interval->d; ?> <?php } } ?> Can anyone help me with what I have wrong? Many thanks (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 Hi guys, I'm putting together a small event system where I want the user to add his own date and time into a textfield (I'll probably make this a series of drop-downs/a date picker later). This is then stored as a timestamp - "0000-00-00 00:00:00" which displays fine until I try to echo it out as a UK date in this format - jS F Y, which just gives today's date but not the inputted date. Here's the code I have right now: Code: [Select] $result = mysql_query("SELECT * FROM stuff.events ORDER BY eventdate ASC"); echo "<br />"; echo mysql_result($result, $i, 'eventvenue'); echo ", "; $dt = new DateTime($eventdate); echo $dt->format("jS F Y"); In my mysql table eventdate is set up as follows: field - eventdate type - timestamp length/values - blank default - current_timestamp collation - blank attributes - on update CURRENT_TIMESTAMP null - blank auto_increment - blank Any help as to why this could be happening would be much appreciated, thanks. Hi there, I have a string '12/04/1990', that's in the format dd/mm/yyyy. I'm attempting to convert that string to a Date, and then insert that date into a MySQL DATE field. The problem is, every time I try to do so, I keep getting values like this in the database: 1970-01-01. Any ideas? Much appreciated. Hi, Currently I am making a module for joomla. every article has an publish date, if the article was published in 7 days ago, it will displayed as "article in last week", My idea is to use today's date - publish date, if the result is greater than 7 and smaller than 14, the article will be displayed as "article in last week. Any one know how to write this code? Here is what I have got, but not working. <?php $todays_date = date("Y-m-d"); $result = mysql_query("select * from jos_content where $test between $todays_date-14 and $todays_date-7"); while($row = mysql_fetch_array($result)) { echo "$todays_date - $row[title]"; } ?> Hi, I am trying to convert a String date into numeric date using PHP function's, but haven't found such function. Had a look at date(), strtotime(), getdate(); e.g. Apr 1 2011 -> 04-01-2011 Could someone please shed some light on this? Regards, Abhishek Hi Guys.. How can I change a date on the fly ? Everything is UTC on my server. How can I change a date to something else on the fly? Ie: $timezone = "cet"; $datetime = "2011-09-04 19:53:00"; echo $datetime($timezone); So I can give it a datetime and have it echo the datetime as if it were in the other timezone? Thanks Graham i have a table that shows payments made but want to the payments only showing from a set date(06/12/14) and before this date i dont want to show
this is my sql that doesnt seem to work and is showing dates before the specified date.
.
"SELECT * FROM payments2014, signup2014, editprop2014 WHERE signup2014.userid = payments2014.payment_userid AND editprop2014.prop_id = signup2014.prop_id AND signup2014.userid !='page1' AND signup2014.userid !='page6' AND signup2014.userid !='page4' AND payments2014.payment_transaction_status !='none' AND payments2014.payment_transaction_status !='CANCELLEDa' AND payments2014.payment_type !='deposit' AND payments2014.payment_paid_timestamp NOT LIKE '%2012%' AND payments2014.payment_paid_timestamp NOT LIKE '%2011%' AND payments2014.payment_paid_timestamp >= '06/12/14' ORDER BY payments2014.payment_id DESC"i have some other parts in the statment but this one that should be filtering is host_payments2014.payment_paid_timestamp >= '06/12/14'thanks in advance |