PHP - Timestamp, M/d/y
What is the proper way to turn a date that is in "m/d/Y" format, into a correct timestamp. When I try strtotime, then try to change it back to a date, it shows up incorrectly (defaulting to the 1969 date that it does
when it messes up. I just need to be able to turn $date = '10/15/2011'; to and from a timestamp correctly. Any advice? Similar TutorialsHey there, Thanks for taking the time to read my thread. I've encountered a problem that I cannot figure out a way to solve. I need to calculate the remaining days until a specified unix timestamp. I haven't yet figured out how to get the amount of days until the timestamp. If anybody could tell me how to get the remaining days until a unix timestamp I would be grateful, thanks. I have this date in database I must convert it to Unix Timestamp How ? 2010-11-11 09:04:44 I try this echo mktime($mydate); but its not work its return wrong Timestamp becase if I convert back it I have wrong date 2011-02-16 21:01:33 Hi, I have in my DB a column with a timestamp as definition. Now I would like to have only the month and year of that column for further use in a form. How can I achieve that? Thanks! How do i correctly update a timestamp? Code: [Select] $date = date("Y-m-d H:i:s"); mysql_query("UPDATE mmembers set time=now() where email=$myusername"); I have a update query that should be updating the timestamp when a "month" field is changed. I have the following code:
$month_update->bindParam(':timestamp', strtotime (date("Y-m-d H:i:s")), PDO::PARAM_INT);
The result that is returned is 1403198033. I need it to look like this 2014-03-26 07:09:06. I know I am missing something and I would greatly appreciate your help.
Thank you so much!
$epocTime = $math.newInt($math.divide("$today.getTime()", "1000"))) I've been looking at converting my php timestamps to display as month, day, and the hour and minute the event occurred on, i tried; Code: [Select] $time = date("j/n H:i", $Events['timestamp']); But no success can anyone point me in the correct direction? Thanks Hi am trying to add date and timestamp of when a comment gets posted.Am not gr8t at php but still learning. If any one can help me on this would be reil gr8t. Sry for the long post. As for now i have this Code: [Select] $date = date("M j, y, g:i a"); and echo's out the date, time [/code]$date[/code] as in the current date and time which i dont want. Code: [Select] <?php $query = yasDB_select("SELECT * FROM newsblog"); if($query->num_rows == 0) { echo '<div id="newsblog_text">This news blog has no comments, become a member and be the first to add one!</div>'; } else { $query = yasDB_select("SELECT * FROM newsblog WHERE userid = '$id'"); while($row = $query->fetch_array(MYSQLI_ASSOC)) { $date = date("M j, y, g:i a"); $text = $row['comment']; $text = str_replace(':D','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/biggrin.gif" title="biggrin" alt="biggrin" />',$text); $text = str_replace(':?','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/confused.gif" title="confused" alt="confused" />',$text); $text = str_replace('8)','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/cool.gif" title="cool" alt="cool" />',$text); $text = str_replace(':cry:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/cry.gif" title="cry" alt="cry" />',$text); $text = str_replace(':shock:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/eek.gif" title="eek" alt="eek" />',$text); $text = str_replace(':evil:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/evil.gif" title="evil" alt="evil" />',$text); $text = str_replace(':lol:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/lol.gif" title="lol" alt="lol" />',$text); $text = str_replace(':x','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/mad.gif" title="mad" alt="mad" />',$text); $text = str_replace(':P','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/razz.gif" title="razz" alt="razz" />',$text); $text = str_replace(':oops:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/redface.gif" title="redface" alt="redface" />',$text); $text = str_replace(':roll:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/rolleyes.gif" title="rolleyes" alt="rolleyes" />',$text); $text = str_replace(':(','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/sad.gif" title="sad" alt="sad" />',$text); $text = str_replace(':)','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/smile.gif" title="smile" alt="smile" />',$text); $text = str_replace(':o','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/surprised.gif" title="surprised" alt="surprised" />',$text); $text = str_replace(':twisted:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/twisted.gif" title="twisted" alt="twisted" />',$text); $text = str_replace(':wink:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/wink.gif" title="wink" alt="wink" />',$text); echo '<div class="newsblog_box1"><div class="newsblog_name">' . $row['name'] . ' '.$date.'</div></div> <div class="newsblog_box2">' . $text . '</div>'; } }?> Hi. I have this code which input data to the database. Code: [Select] <?php include("connect.php"); echo $date = date("Y-m-d H:i:s"); echo "\n <br />"; echo $date2 = date('Y-m-d H:i:s', strtotime("+20 seconds")); mysql_query("UPDATE users2 SET date2 = '$date2'"); $query = mysql_query("SELECT date2 FROM users2"); $numrows = mysql_num_rows($query); if ($numrows != 0) { while ($row = $mysql_fetch_array($query)) { $date_final = $row['date2']; } } echo $date_final; ?> Variable date2 is stored as timestamp. Now i want to display this two variable on the web, but this code doesn't work. Why? Thank you. I need to set two variables for use within my pages, one containing a date as a string in format 'YYYY-MM-DD HH-MM-SS' and another containing the same date as a timestamp. The date and time stored will take on the value passed in the url if available, else will be for the current date. The time should always be midnight at the beginning of the date. eg. $datestr = '2010-09-08 00:00:00' and $datestamp = '1283904000' Where a date is passed in the url, it will be in the format 'YYYY-MM-DD'. The problem I am having is getting an accurate timestamp. I think the trouble is connected to the handling of daylight saving time as it it always an hour out. What I have at the present is as below: Code: [Select] <?php // ensure all date and time functions are relative to the correct timezone (UK) date_default_timezone_set('Europe/London'); // string holding selected / current date in format 'YYYY-MM-DD HH:MM:SS' $datestr = (isset($_GET['date']) ? $_GET['date']." 00:00:00" : gmdate("Y-m-d")." 00:00:00"); // int holding selected / current date as unix timestamp $datestamp = strtotime($datestr); ?> Can anybody give me a simple way of converting $datestr into $datestamp to ensure that this is always correct for my UK timezone, irrespective of whether we are in or out of daylight saving time? Hey there, Thanks for taking the time to read my thread. My issue is if I'm given a time stamp in PHP how could I calculate the number of days until that time stamp?. Thanks for your time. I have a timestamp field in my mySQL table and need to check if it's 14 day or older. What's the best way to do this? Any help will be appreciated Hello! I'm trying to develop some kind of RSS news aggregator and I want to show only feeds younger than 1day. I figured i could transform RSS pubDate to timestamp (strtotime()), but there are some feeds without timestamp (like: http://izklop.com/xmldata/rsslinks.xml). Is there any other way to do it, so I could find timestamp from those feeds without pubdate? If there isn't any other way, do You think it is ok, to just show last 5 feeds? I hope I made my self clear, and please forgive me for my English I need some help. I have this script that pulls timestamps from the database. What I want to do is create a count of how many of those timestamps that were returned were from the morning(6am-12pm), Afternoon (12pm-6pm), Evening (6pm-12am), or Night (12am-6am). How do I do I parse the timestamps to do that and display the count. Thanks! Code: [Select] <?php /** * @author William Morris * @copyright 2010 */ include('inc/db.php'); //function to show date and time based on timestamp function showTIME($timestamp){ $date = date('F j Y h:i:s A', $timestamp); return $date; } $startdate = "2010-07-01"; $enddate = "2010-08-05"; //query to pull time stamps in between dates //convert dates into timestamp //$startdate = strtotime($_POST['startdate']); //$enddate = strtotime($_POST['enddate']); //convert dates into morning timestamp $startdate1 = strtotime($startdate."06:00:00"); $enddate1 = strtotime($enddate."11:59:59"); $sql = mysqli_query($conn, "SELECT event_time FROM event WHERE event = 'Registration' AND event_time BETWEEN '$startdate1' AND '$enddate1'"); while($row = mysqli_fetch_array($sql)){ echo showTIME($row['event_time'])."<br>"; } ?> How would I go about adding a timestamp to my image uploads so I don't erase image files with the same name? Also, what would be the correct use of the mysql_escape_string <?php require_once('storescripts/connect.php'); mysql_select_db($database_phpimage,$phpimage); $uploadDir = 'upload/'; if(isset($_POST['upload' . $config])) { foreach ($_FILES as $file) { $fileName = $file['name']; $tmpName = $file['tmp_name']; $fileSize = $file['size']; $fileType = $file['type']; if($fileName==""){ $filePath = 'upload/'; } else{ $filePath = $uploadDir . $fileName; } $filePath = str_replace(" ", "_", $filePath); $result = move_uploaded_file($tmpName, $filePath); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $fileinsert[]=$filePath; } } $mid = mysql_real_escape_string(trim($_POST['mid'])); $cat = mysql_real_escape_string(trim($_POST['cat'])); $item = mysql_real_escape_string(trim($_POST['item'])); $price = mysql_real_escape_string(trim($_POST['price'])); $about = mysql_real_escape_string(trim($_POST['about'])); $fields = array(); $values = array(); $updateVals = array(); for($i=1; $i<=4; $i++) { $fields[$i] = 'name'.$i; $values[$i] = mysql_real_escape_string(basename(trim($_FILES[$fields[$i]]['name']))); if($values[$i] != '') { $updateVals[] = "{$fields[$i]} = '{$values[$i]}'"; } } $updateNames = ''; if(count($updateVals)) { $updateNames = ", " . implode(', ', $updateVals); } $update = "INSERT INTO image (mid, cid, item, price, about, name1, name2, name3, name4) VALUES ('$mid', '$cat', '$item', '$price', '$about', '$values[1]', '$values[2]', '$values[3]', '$values[4]') ON DUPLICATE KEY UPDATE cid = '$cat', item = '$item', price = '$price', about = '$about' $updateNames"; $result = mysql_query($update) or die (mysql_error()); $id = mysql_insert_id(); ?> <p style="font-size:35px; font-family:Arial, Helvetica, sans-serif; color:#255E67; margin-left:25px;">Your Item Has Been Uploaded!</p> <script type="text/javascript"> setTimeout('ourRedirect()', 2000) function ourRedirect() { location.href='protator_php.php?mid=<?php echo $id ?>' } </script> Hi, I have a MySQL table with a timestamp field. I want this field to be automatically updated with the current date and time when a record is updated. How do I do that? This is my update query. Thanks: Code: [Select] $Sql="UPDATE MyTable SET client_alias='$client_alias',testimonial_date='$testimonial_date',order_ontime='$order_ontime',how_deal='$how_deal',order_condition='$order_condition',happy_colour='$happy_colour',colour_chosen='$colur_chosen',easy_use='$easy_use',effectiveness='$effectiveness',client_comments_eng='$client_comments_eng',client_comments_esp='$client_comments_esp',testimonial_updated_by='$testimonial_updated_by', _time_stamp='?????????' WHERE id_testimonial='$colname_testimonials_update_RS'"; mysql_query($Sql) or die('Error, query failed : ' . mysql_error()); I have a little problem with creating a timestamp and display it again with date () Here is a small shript: <?php $day = 6; $month = 7; $year = 1985; $ts = mktime($month, $day, $year); echo date("d-m-Y",$ts); ?> In my world would result in 6-7-1985 but instead I get 06-11-2010 Why .. what am I doing wrong? POSTBIL.COM any one know of any scripts to archive news items by timestamp? google searches just show tonnes of news archives.. not what i want! obviously using php, all news items have a timestamp, how would i go about this? very open ended question but ANY help would really be appreciated. Thanks! I have a column that is named date_created and has a value of DATETIME. How on this script can I insert only the time it was created. Is it NOW()) and if so how do I write it in the script? Code: [Select] // if residential if($_POST['type'] == ""){ mysql_select_db("", $con); $sql = "INSERT INTO apartments (username, title, county, town, type, description, phone, rooms, bath, square, rent, fees, service, imageurl1, imageurl2, imageurl3, imageurl4) VALUES ('".$myusername."', '".mysql_real_escape_string($_POST['title'])."', '".mysql_real_escape_string($_POST['county'])."', '".mysql_real_escape_string($_POST['town'])."', '".mysql_real_escape_string($_POST['type'])."', '".mysql_real_escape_string($_POST['description'])."', '".mysql_real_escape_string($_POST['phone'])."', '".$_POST[('rooms')]."', '".mysql_real_escape_string($_POST['bath'])."', '".mysql_real_escape_string($_POST['square'])."', '".mysql_real_escape_string($_POST['rent'])."', '".mysql_real_escape_string($_POST['fees'])."', '".mysql_real_escape_string($_POST['service'])."', '".mysql_real_escape_string($images[1])."', '".mysql_real_escape_string($images[2])."', '".mysql_real_escape_string($images[3])."', '".mysql_real_escape_string($images[4])."')"; $result = mysql_query($sql) or die(mysql_error()); Hi, I have a table field that has the full timestamp (date and time), I want to select records from DB but after checking the date part only from the timestamp. Example: 2020-3-10 10:15:00 ---- i want to check if current date is equal to the date part which in this case it is the same. Thanks. |