PHP - Hot Get Time And Put In Database
Anyone can help me how to get the time when log.in and the time when log.out then it will store in database... tnx
Similar TutorialsI am trying to find a way of deleting entries from a database after a certain time, and also when there is another field in the database set to 0. i have got so far with the code (will delete when other field is at 0) but nothing happens when i try to add in the time. my code im trying to use is below mysql_query("DELETE FROM temp_users WHERE book_stage='0' and WHERE time() > [creation+60]"); creation being the name of the field in the database that holds the unix time stamp of when the entry was created. i need the entry to be deleted one hour after it was created if the book_stage hasnt been changed to 1 during this hour. many thanks, gavin I have my database set to insert the current time stamp when an entry is made into the table, I am then trying to retrieve via the following code: $select_view_idea="SELECT * FROM $tbl_name5 WHERE message_number='$message_number'"; $result_view_idea=mysql_query($select_view_idea); while($row_view_idea=mysql_fetch_assoc($result_view_idea)){ extract($row_view_idea); } date_default_timezone_set('US/Eastern'); $date=date('l, F jS Y h:i:s A T', $date); echo $date; The above is outputting: Wednesday, December 31st 1969 07:33:31 PM EST the database contains: 2011-11-18 00:47:56 did some searching on the internet and didnt find much. i have created an online classifieds website and want all created listings to expire and delete after a certain amount of days. honestly i have no idea where to start with this implementation. cookies were the only thing that even crossed my mind... any ideas? btw each listing is stored in a table called ob_listings Currently the date is stored in the database as 28-02-2011 - 21:00:30 and the variable is: $date['mTime'] How can I format it too look "pretty" like this: February 28, 2011 - 10:00 PM? (don't need the seconds) Pls anyone tell me to connect database Hello, I am trying to subtract the current time from a list of times in a mysql database. The first page inserts the time into mysql.
<?php $var_Time = date("h:i:s"); $mysqli = new mysqli('localhost','root','blah','test'); if ($mysqli->connect_error) { die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error); } $insert_row = $mysqli->query("REPLACE INTO test_table (id, time) Values(NULL, '$var_Time')"); if($insert_row){ while (false); }else{ die('Error : ('. $mysqli->errno .') '. $mysqli->error); } $mysqli->close(); ?>The second page is supposed to iterate through all of the times in the database and subtract the current time, but i cant figure out how to do it. <?php $mysqli = new mysqli('localhost','root','blah','test'); if ($mysqli->connect_error) { die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error); } $query = "SELECT * FROM `test_table`"; $result = $mysqli->query($query) or die($mysqli->error.__LINE__); $var_set_time = stripslashes($row['time']); $var_current_time = date("h:i:s"); $diff = strtotime( $var_current_time .' UTC' ) - strtotime( $var_set_time .' UTC'); echo $diff; ?> Edited by Ch0cu3r, 09 October 2014 - 01:40 PM. Added code tags I have the date stored as: date( "d/m/Y" ) After it's pulled from the database, I would like it to display like: date( "F j, Y" ) I have tried below, but the output makes d the month and m the day. $dateStamp = strtotime($row['startrepeat']); $dateFormatted = date("F j, Y", $dateStamp); Hi, I have a project where i want to send the sms to the customers at the particular time calling from the database, how to do these in php? Thanks, Hi, I have a problem. i want to show the current date and time in my tables of the database. I want to show it because i want to show it on my report generated in php. By the way i do not have a "date" field in my form. Can anyone help me out? Thanks, Heshan. hiii all, i want to show the database field (alise name) as the url after index.php when page or site loads first time. how i can achieve it? please help.... thanks in advance 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 Basically I have recently been playing around with parsing a csv file. What I am looking to do at this point is simply take the date/timestamp (part of the csv file), which is in the following format:DD/MM HH:MM:SS.100th/s For the sake of argument, lets say I have this in an array string called $csv[0] and the file has several lines that span the course of a couple hours. I wouldn't mind having to use explode() to breakup/remove the date or 100th/s IF that would make things a lot simpler. So where would I start in trying to achieve this?. The result I am looking for will simply return "X Seconds". Storing this in a string variable would be a bonus, as I plan to use this to divide a separate piece of information. Any examples or ideas would be great. Thank you. ps: Here is an example time from the csv file itself: Code: [Select] 11/19 22:23:18.143 I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution! $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative) echo $ad_start; $current_time = time() . "<br />"; // current epoch time echo $current_time; $days_past = $ad_start - $current_time; // days past echo "<br />$days_past days have past since the ad started!<br />"; if($days_past <= 14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; } 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!
What are the differences and implications of UTC time and Zulu time? <?php function getArr(string $time):array { $dateTime = new \DateTime($time); return [ 'time'=>$time, 'timestamp'=> $dateTime->getTimestamp(), 'dateTime' => $dateTime ]; } $arr = getArr('2020-08-05'); $arr_z = getArr('2020-08-05T00:00:00Z'); print_r($arr); print_r($arr_z); echo('equal timestamps: '.($arr['timestamp'] === $arr['timestamp']?'true':'false'));
Array ( [time] => 2020-08-05 [timestamp] => 1596585600 [dateTime] => DateTime Object ( [date] => 2020-08-05 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) ) Array ( [time] => 2020-08-05T00:00:00Z [timestamp] => 1596585600 [dateTime] => DateTime Object ( [date] => 2020-08-05 00:00:00.000000 [timezone_type] => 2 [timezone] => Z ) ) equal timestamps: true
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. PHP 5.2.6 We rent PHP server space on a server in California. Several of my pages generated by PHP show the current date and time, so when the page is printed, the user knows when the data was printed. Our users could be anywhere in the US, I am in Michigan. How do I convert the server time (PDT) into local time, regardless of where the user is? Thanks. This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=316461.0 Hello, I tried to implement some PHP code to enable a web page to show "Dinner" specials versus "Lunch" specials based on the time. The business is located in the Eastern Time Zone, so I only need to routine to work based on Eastern Time (New York). What I am noticing is that the server is processing the lines of code so fast that the command to establish the correct time for the remaining code is not always being acknowledged. This line of code appears to be processing too fast for the remaining lines of code: date_default_timezone_set ( "America/New_York" ); Is there some additional code I can put in place to make sure the correct time is always ascertained? I need the $hourmin variable to always return a combination of hour + minute based on 24-hour time and Eastern Time zone. My code is as follows: <?php $name8 = file_get_contents("test/special8name.txt"); date_default_timezone_set ( "America/New_York" ); $gethour = date("H"); $getminutes = $gettimedate["minutes"]; $gettimedate = date(); $hourmin = $gethour . $getminutes; $currentday = date("l", time()); $currentdate = date("M j, Y"); if ($hourmin < 1500 && $currentday <> "Saturday" && $currentday <> "Sunday") { echo "<span class=\"namesred\">$name8 </span>"; } else if ( $hourmin > 1500 && $hourmin < 2300 && $currentday <> "Saturday" && $currentday <> "Sunday") { echo "<span class=\"namesblue\">$name8 </span>"; } else if ( $currentday == "Saturday" or $currentday == "Sunday") { echo "<span class=\"namesblue\">$name8 </span>"; } ?> I am making a time clock, and I was wondering what is the best way to calculate the number of hours an employee worked? I have a table called "statuses" it holds names of punch types: - id = the auto_inc - status = "in/out/break/lunch" text statuses - paid = whether or not the punch is paid or not (true/false) I have another table called "logging" This table holds the information about the punch type: - id = the auto_inc - owner = the member id - ip = members ip - inout = the punch type from the statuses table - location = the city/state of where the punch took place - date = the time the member punched Maybe I am over thinking this, but what is the best way to calculate the hours a person has worked? Right now I am getting all the punches for for a particular member between a date range. then loop through the data to display it and passing it to a method in a class called Calc. I want to then add the times from punch in to punch out, then the next punch in to punch out. Any suggestions? |