PHP - Simple Date/time Question
I'm trying to convert the following time stamp: 12:03PM to military time 13:03.
I'm using the following code, but it's just outputing 12:03: $sampledate=("2010-11-08, 12:03PM CST"); $xplodeDateStamp = explode(", ", $sampledate); $xplodeDate = $xplodeDateStamp[0]; $xplodeTime = $xplodeDateStamp[1]; echo "Date: " . $xplodeDate . "<br>"; echo "Time: " . $xplodeTime . "<br>"; echo "Military Time: " . date("H:i",strtotime("$xplodeTime")); Similar TutorialsHi, I am new to this forum as of now. I have a question which probably has a very straightforward answer but I just can't solve it. I am using mysql and have the following code: while($row=mysqli_fetch_array($result)) { $time1=date("j F Y G: i", $row[1]); echo "<tr><td>$row[email]</td>"; echo "<td>$time1</td>"; echo "<td>$row[comment]</td></tr>"; } It is the first line in the curly brackets that is causing the problem. If I replace $row[1] with $time I get today's date/time. But I need the date/time from what has been input so that won't work. Can anyone explain to me what is wrong with my code please? It gives the following error message: Notice: A non well formed numeric value encountered in C:\xampp\htdocs Thanks very much It seems like this is a question that may be on here already, but I couldn't find it with a search, so I apologize. I am given a string that represents a datetime, and it is always in this format: HH:mm:ss MMM DD, YYYY PDT. I just want to turn that into a proper format for mysql (Y-m-d H:i:s), but I'm not exactly sure how to go about that. (I could do this in C# rather quickly!) Probably a simple question, I hope someone can help! Thanks. Hey guys, How would I go about subtracting Today from a previous day to find the difference? For example, I want to subtract TODAY from a previous date in my database, to determine if the difference is greater than 1 day. Any ideas? I tried doing the subraction in TIMESTAMPS, but when I convert the date back to Y-m-d H:i:s, I got some weird year and time. Hi there, I've just started learning php and mysql today. I'm putting things together in dreamweaver and everything is running smoothly (ish). I've got a form written in php that sends data to a database. All fine. I need to send the time of submission to the database. I've put in a hidden field, what code should I use to set the field value to a mysql field of type DATETIME? Cheers. PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel OK So I've got a datepicker that sends a date in d/m/y format. My DB stores the data in Unix Timestamp Which I can convert the date to with strtotime however this does the exact date & time. All I want is the actual day. I've spent hours trying to convert this with just the day with mixed results... Thanks. I am having a problem with PHP displaying the correct date and time. It updates as it should, but is fast by 4min and is always displaying a date in 2004. I ran a basic php script to make sure the application im using itself is not wrong. go to lunenburgledger.com/time.php Anybody had any ideas on where to check? The system time on the Windows Server 2003 is correct. The only thing I can think of is that it was converted to a virtual machine on vmware esxi, but the system time stayed right. Any ideas? Thanks! Hey, I need help with my date & time string. I need to edit it do show in a string + also use it for calculating things like when the date has passed. The string is like this: Code: [Select] <?php $string = '2011-01-01 00:00 AM'; ?> So i wanted to check if there was a function that can automatically convert it, so it would say for example: Quote Sunday, 1st of January 2011 00:00 AM But at the same time compare $string against server time to see if the date has expired? Hope you can help Hey, I need help with date, I have stored dates in my table in this format: i.e. 22.10.2011 but now use timestamp to store dates. Problem is with this query the WHERE clause will find dates in the old format and I want to change that to the new format. Code: [Select] for($i = $count; $i > 0; $i--) { $day = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") - $i, date("Y"))); $tmp = mysql_fetch_array(safe_query("SELECT count FROM ".PREFIX."counter_stats WHERE dates LIKE '%".$day."'")); $array[] = $tmp['count'] ? $tmp['count'] : 0; } Am I making sense ? What is the best way to insert this time stamp into mysql? This is the info I want... Example: Sunday, 28.1.11, 9:56 How would I also select time from the database using mysql? I have a batch script that reads from a timestamp.txt file to determine the last time it ran and I need to modify that by two hours. What happens is the script will run to look for changes in the county records and their server time is two hours different from mine. Code: [Select] $fr=fopen("xml/timestamp.txt",'r'); $mydate=fread($fr, 50); if ($incremental_updates == 1){ $default_template_file="xml/incremental_template.xml"; $default_config_name="xml/incremental.xml"; $contest=file_get_contents($default_template_file); $contest=str_replace("{DATE_TAG}", $mydate, $contest); $f=fopen($default_config_name,'w+'); fwrite($f, $contest); fclose($f); fclose($fr); $fw=fopen("xml/timestamp.txt",'w'); fwrite($fw, substr(date('c'), 0, 19)); fclose($fw); }else{ $default_config_name = "xml/full_update.xml"; } I tried making a time stamp update look like $cur_timestamp=date("Y-m-d H:i:s", time() +14400); which is correct but it doesn't write to the text file properly. Using the above fwrite($fw, substr(date('c'), 0, 19)); I get the correct results in the timestamp.txt file for my server time. I need it to be +14400 2011-05-25T08:27:51 would essentially become 2011-05-25T10:27:51 when it writes to the timestamp.txt I hope that makes sense. J Hi! The below dropdown will show dates/times every 15 minutes from 12am to 11:45pm for only 1 day. I want it to show for 5 days, anyway I can do this? Below code: Code: [Select] $start = strtotime('12:00am'); $end = strtotime('11:45pm'); echo '<select name="time">'; for ($i = $start; $i <= $end; $i += 900) { echo '<option>' . date('F j, Y, \a\t g:i a', $i); } echo '</select>'; Thanks for any help. I have a field set as datetime and want to compare that field to see if it is older then ten minutes. Can anyone help I am having a brain fart? I'm looking to enter the current time and date into a mysql database using php. My current code looks like this: Code: [Select] $now = date("m/d/y",time()); I then insert $now into the table into a datetime column. This all works but the time when read from the column appears as 0000-00-00 00:00:00. Any ideas what I'm doing wrong? Thanks in advance. Hello, first time poster here and PHP newbie. I was directed here by the html forum. I need help adding a time + date stamp to videos I upload to my web page. I have searched this and other formus and not seen a similar query / solution. Here is my page: http://ob-kc.com/tl.html The thumbnails are linked to their respective timelapse videos. Between the thumbnail itself and the label (i.e. '7 am - 8 am') I would like to add 'Updated x/x/2011 @ xx:xx:xx' Any suggestions on the cleanest way to do this? Hugh hello i got this small function i`m working on to get the date of a month something like get current date - 1 but not sure how to handle jan month can someone help me please ? $month = date('m') - 1; $date_startt = date('Y').'-'.$luna.'-01'; $timestamp_start = strtotime($data_start); I'm having some trouble understanding how to use date and time when updating my database. The table is already populated with Date and Time fields in date and time format. I need to update the table based on the date and time, but I can't make it work. I tested all the variables and they are being sent correctly. I'm pretty sure the problem lies in how I'm trying to match the Date and Time fields with $dateID and $timeID in the WHERE part of the query, but I'm not sure how to fix that! Code: [Select] <?php include("opendatabase.php"); $size = count($_POST['player1']); $i=0; $thisyear = date("Y"); while ($i < $size) { $dateID = $_POST['date'][$i]; $timeID = $_POST['time'][$i]; $player1 = ($_POST['player1'][$i]); $player2 = ($_POST['player2'][$i]); $player3 = ($_POST['player3'][$i]); $player4 = ($_POST['player4'][$i]); $player5 = ($_POST['player5'][$i]); mysql_query(" UPDATE Daysheets$thisyear SET Player1='$player1', Player2='$player2', Player3='$player3', Player4='$player4', Player5='$player5' WHERE Date = '$dateID' AND Time = '$timeID' "); $i++; } header("Location: /teetimes/publicteetimes.php?teetimedate=$dateID"); mysql_close($con) ?>Any help appreciated! I should also mention that whenever I run this query it erases anything that was previously entered in the database except the date and time columns... I just recalled using date(); time() for lots of things in my database, including post times etc. At first I simply assumed this used server time or something, but when I changed my PC's time, it changed ! Now, shortly after this I simply assumed this was because of me using a localhost? But I am not certain anymore.. If I would place this online, would date() and time() return you server time or user time? I couldnt find it on google =-( hi, I have some code that deals with sending out reminders for appointments due the following day. So if today is the 21/3 then only reminders for appointments due on the 22/3 should be sent. Currently this isn't happening... If reminders are sent on 21/3 at 9.50 am, my code adds 24 hours to this datetime and sends reminders due for all appointments that fall bewteen 21/3 9.50am and 22/3 9.49 am. What I want to do is simply send all reminders for appointments that are on the 22/3 exclusive of time. I'm not sure how do this in php, which uses the unix datetime format to mildy complicate issues anhy help or solutions would be massive, thanks.how to Code: [Select] $days = time() + (1 * (60 * 60 * 24)); $apts = $db->fetch_all('status = 1 AND time > ? AND time < ?', array(time(), $days)); |