PHP - Question About Unix Time
After doing some reading im trying to make sure I understand how all this time stuff works with using sql
I have a Session created for users that uses $_SESSION['login_time'] = time(); when I echo that it comes up as 1324245123. so the reason it looks like that is because that is what UNIX looks like? So thats why this code doesnt work if ($get1['date'] > strtotime('-1 minutes')) { because the date im getting from $get1 is a sql time stamp and the strtotime is UNIX and they dont match do I understand this right? Similar TutorialsOK 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. What needs to be changed to make this work... Code: [Select] // Build query. $q2 = "UPDATE member SET logged_in=?, last_activity=time(), updated_on=NOW() WHERE id=? LIMIT 1"; Apparently PHP doesn't like time() Debbie Code: [Select] for ($z=1;$z<=30*365; $z++) { $bal[date('Y-m-d', strtotime("+ ". $z ." days"))] = $balance;//the balance of loan here.; } As you can see Im working on loading the daily balance of a 30 year loan in an array. The code goes to hell in the year 2038. I have scoured the internet for help. I have gone to the wikipedia link and have looked at other posts but there isn't quite something that can help me. How can I load dates beyond 01-18-2038 into my array? I have heard of ways to do it with MySQL and the DATETIME() function, but that doesn't seem to make sense for what I am trying to accomplish. Please point me in the right direction. Thanks. I have to two variables $cronlast and $cronnow in my php code. I need to have the time 7am of previous day in $cronlast variable and 7am today in $cronnow variable. I need the time in UNIX timestamp format. So everyday when I print the variable I should have: $cronlast=7am Yesterday(in Unix Timestamp) $cronnow=7am Today(in Unix Timestamp) I would appreciate any help. Hello. I have a mysql database with an 'entrytime' field which contains the unix timestamp the record was added. How do I create a mysql query to select all records for a given month/year? For example, if I wanted to create a query to display all records for October 2010 how do I go about it? I am at a loss and can't find my answer via google. Thanks in advance for any help! I have a datetime table in my db. my time stamps look like this 2011-09-28 16:34:03 My question is this If I have a time in of 2011-09-28 10:34:03 and a time out of 2011-09-28 18:04:03 how can I figure out the hours worked? Any help is appreciated. I need to create some sort of queuing system for my php application to function properly. I was just going to a simple one with a column named "enqueued" and have a queued table that has id, start_time, stop_time. It's more like an ordered "delayed" queue system.. eh whatever. Anyways, what would be the best way to store and access the times in the database? I'm supposing I can just use a TIMESTAMP and have the default value set to TIMESTAMP for the start_time, how how about stop_time I'm assuming still a TIMESTAMP, but with no default value and it can't be null. But, how would I do the time in php? Like adding an amount to a timestamp.. and is there any special functions I can use to read the results from the mysql timestamp fields? Let's say I wanted to take a timestamp of now and add 40 minutes to it.. how do I do this? Does time zone change have to occur in an INI file, or can I place it as a value. I've tried using default_time_zone ('America/New York') but had no success with it, even to just ECHO a statement that says: It is now 3:50PM in New York. Hi, 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 Hello everyone, With the recent time change, I found a new problem with my code. I think I have it fixed by utilizing the "date_default_timezone_set()" function, but I have a question. Does this php time/date function automatically account for daylight savings time, is it something that will have to be adjusted in my code? I think I can figure out how to adjust it if it's needed, but I don't want to have to do the work if it is updated automatically. Thanks for any help. How do you execute commands on Unix box using a PHP script? 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. 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")); I'm interested to know how other people keep track of time and also how they display time correctly back to the users. I'm using a third party API that I can tie into that actually gives me the userID of a user, their full name and the timezone for that user. After checking a few users data, this is an example data of what I'm working with. userID: 234213412 first_name: foo last_name: bar timezone: -6 Basically when a user visits my web app, I create a new account for them and store the above data. Currently, I'm just fetching the result from time() and converting it into MySQL DateTime format and storing that into my database. Code: [Select] //get the current time as an integer $php_timestamp = time(); //formats the time according to MySQL DateTime type $this->mysql_formatted_time = date('Y-m-d H:i:s', $php_timestamp); I would think the current way that I'm doing this is not very good because there is a possibility that I could introduce load balancing servers into the mix and they might not be located in the same region. Also, I would have no idea how to factor the time and modify it according to the timezone value.(in my above example, -6) Can anyone help me decide what method I should use to keep all of my servers timestamps in sync and how to display the time to the end user so that it looks correct to them? I want to convert a unix time stamp to the date format (dd/mm/yy). How can i be possible ? Hi, I am in the process of switching over to a unix server, and I found the dir program I use in development now sorts the unix way by date ! MySQL client version 5.1.52 PHP latest Below in my script how do I change the output to sort by name please <html> <head> <title>DIR</title> </head> <link rel="stylesheet" type="text/css" href="../../css/tableLL.css"> <body> <?php function humansize($size) { $kb = 1024; // Kilobyte $mb = 1024 * $kb; // Megabyte $gb = 1024 * $mb; // Gigabyte $tb = 1024 * $gb; // Terabyte if($size < $kb) return $size."B"; else if($size < $mb) return round($size/$kb,0)."KB"; else if($size < $gb) return round($size/$mb,0)."MB"; else if($size < $tb) return round($size/$gb,0)."GB"; else return round($size/$tb,2)."TB"; } // get local directory path $path= dirname($_SERVER['SCRIPT_FILENAME']); ?> <h3>Files in <?php print $path; ?>:</h3> <ul> <?php $d = dir($path); $icon = ''; while (false !== ($entry = $d->read())) { if ( substr($entry, 0, 1)=='.' ) continue; // get size $size = filesize($path.'/'.$entry); $humansize = humansize($size); // find filename extension $dotpos = strrpos($entry, '.'); if ($dotpos) { $ext = substr($entry, $dotpos+1); if ($ext === 'jpeg' || $ext === 'gif' || $ext === 'png') { $icon = "<img src='$entry' style='width: 48px; height: auto; vertical-align: text-top;' alt='icon' title='$entry' />"; } } print "<li><a href='$entry'>$entry</a> ($humansize) $icon</li>\n"; $icon= ''; } $d->close(); ?> </ul> <hr width="100%"> I do hope someone can help Regards Topshed Why doesn't this code work... echo '<p>time() = ' . time() . ' seconds</p>'; echo '<p>$lastActivity = ' . $lastActivity . '</p>'; echo '<p>Seconds Active: ' . time() - $lastActivity . ' seconds</p>'; ...where $lastActivity comes from my database. When I run my script I see... Quote time() = 1331187131 seconds $lastActivity = 1331186745 -1331186745 seconds The last line is dropping the label and there is now Date Math?! Debbie sorry, I know this is simple, but stuck on it... how would one go about converting 1/21/11 to a UNIX timestamp, something like 1293035229? and while we are at it, how to convert 1293035229 to 1/21/11 ? (i know the timestamp is wrong, just for example) thanks!!!!! I want to have the timestamps of week numbers, this is working perfectly from the year 2011 to 2012. It refuses to switch to the year 2013. Do anyone know what i'm doing wrong?: <?php $year='2012'; $weekno='01'; $date = strtotime($year.'W'.$weekno); for($i=0;$i<55;$i++){ print date('d-m-Y W',$date)."\n"; $date=(weekno($date,'1'))."\n"; $date=(int)$date; } function weekno($date,$step=''){ $year=date('Y',$date); $weekno=date('W',$date); $date = strtotime($year.'W'.$weekno); if($step>0){ $date = strtotime($year.'W'.$weekno. '+1 week'); } if($step<0){ $date = strtotime($year.'W'.$weekno. '-1 week'); } return($date); } ?> Hi, I have switched to a unix server from a windows one and my dir.php now displays in date order which makes things very hard to find Below is the code I use, can anyone tell me what to put, and where ? to make it sort by file name, or point me to a freeware script that has already invented the wheel so to speak. <?php function humansize($size) { $kb = 1024; // Kilobyte $mb = 1024 * $kb; // Megabyte $gb = 1024 * $mb; // Gigabyte $tb = 1024 * $gb; // Terabyte if($size < $kb) return $size."B"; else if($size < $mb) return round($size/$kb,0)."KB"; else if($size < $gb) return round($size/$mb,0)."MB"; else if($size < $tb) return round($size/$gb,0)."GB"; else return round($size/$tb,2)."TB"; } $path= dirname($_SERVER['SCRIPT_FILENAME']); ?> <h3>Files in <?php print $path; ?>:</h3> <ul> <?php $d = dir($path); $icon = ''; while (false !== ($entry = $d->read())) { if ( substr($entry, 0, 1)=='.' ) continue; $size = filesize($path.'/'.$entry); $humansize = humansize($size); $dotpos = strrpos($entry, '.'); if ($dotpos) { $ext = substr($entry, $dotpos+1); if ($ext === 'jpeg' || $ext === 'gif' || $ext === 'png') { $icon = "<img src='$entry' style='width: 48px; height: auto; vertical-align: text-top;' alt='icon' title='$entry' />"; } } print "<li><a href='$entry'>$entry</a> ($humansize) $icon</li>\n"; $icon= ''; } $d->close(); ?> Please help an old fellow who should know better Regards Topshed |