PHP - Timestamp Problem
upon using PHP strtotime('2010-11-23 00:00:00') output a different values.
Asia/Taipei int(1290441600) Europe/London int(1290470400) Expected : Same since I declare the date that need to convert as timestamp date_default_timezone_set('Asia/Taipei'); var_dump(strtotime('2010-11-23 00:00:00')); date_default_timezone_set('Europe/London'); var_dump(strtotime('2010-11-23 00:00:00')); Any explanation, Idea or alternative? Please help. Thanks Similar TutorialsHi! To calculate my real time hours worked for/at a client I've made 3scripts, 1 to start the time, 1 to show the running time and 1 for stopping it. The first and last are put into my hosted DB. I'm accessing them through SSH so that I don't need my laptop all the time. Now here's the problem, when I start the time and I look into my DB I see the actual correct time and date (timestamp), but when I execute the script for stopping it the start time changes, so for example I started at 9:00, that time will be changed to for example 11:00 when I stop it... very strange, here are my scripts: start: <?php date_default_timezone_set('Europe/Brussels'); $timestamp = date('Y-m-d H:i:s'); $conn = mysql_connect('server' 'user', 'pw') or die(mysql_error()); mysql_select_db('hystudi_timesheets', $conn) or die(mysql_error()); mysql_query("INSERT INTO timesheet (t_start_timestamp) VALUES ('$timestamp')", $conn) or die(mysql_error()); ?> stop: <?php date_default_timezone_set('Europe/Brussels'); $timestamp = date('Y-m-d H:i:s'); $conn = mysql_connect('server', 'user', 'pw') or die(mysql_error()); mysql_select_db('hystudi_timesheets', $conn) or die(mysql_error()); $records = mysql_query("SELECT id, t_start_timestamp FROM timesheet ORDER BY id DESC LIMIT 1"); while ($row = mysql_fetch_array($records)) { $id = $row['id']; $start_timestamp = date("U", strtotime($row['t_start_timestamp'])); } $duration = (date("U", strtotime($timestamp)) - $start_timestamp) / 3600; // duration mysql_query("UPDATE timesheet SET t_end_timestamp = '$timestamp', t_calculated_time = '".round($duration,2)."' WHERE id = $id", $conn) or die(mysql_error()); ?> Anyone sees what I'm doing wrong here? Or could it be my server? It's a shared host 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"); $epocTime = $math.newInt($math.divide("$today.getTime()", "1000"))) 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! Hey 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 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!
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 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? 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 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'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 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 hey guys I wanting some information on the best way to store a timestamp and how I would convert that timestamp to another timezone please?
im guessing I would firstly store all timestamps to the database in GMT OR BST then convert after according to users timezone preference?
Is there a good website for this please on how this is possible...thank you
im having problem comparing timestamps in my where clause for some strange reason...my query works perfect but when adding WHERE it doesn't bring up a result although it should...I've been playing about with it for almost a day now...and it doesn't make sense
unix_timestamp values start_date_time 1406411505 end_date_time 1407275505 now 1406461573my query SELECT i.item_id, i.title, i.price, @start_date_time := CONVERT_TZ(i.start_date_time, '+00:00', u.time_zone), @end_date_time := DATE_ADD(@start_date_time, INTERVAL 10 DAY), @end_date_time AS `end_date_time` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id LEFT JOIN categories c ON c.category_id = sc.category_id JOIN users u ON username = 'Destramic' WHERE UNIX_TIMESTAMP(@start_date_time) < UNIX_TIMESTAMP(NOW()) AND UNIX_TIMESTAMP(@end_date_time) >= UNIX_TIMESTAMP(NOW())if anyone can diagnose my problem I'd it would be much appreciated I've been having problems displaying the correct time when extracting timestamp for a graph. Wasted a lot of time trying to adjust for timezone and then finding that it didn't help. Now trying to add 2 hours to the timestamp and not sure how. Here is the line that needs to be changed I believe.
$Date=substr(mysql_result($result,$i,"Date"),11,5); Can someone help me?
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 I'm using date_default_timezone_set("America/New_York"); to set the time, but the time isn't being displayed properly in mysql. The time is some other time zone. Do I have to set the time in mysql too? How do I do this? 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()); 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> 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! |