PHP - Php Count Timestamp
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>"; } ?> Similar TutorialsHi guys, I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this: Code: [Select] www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp However i have got a error which i don't know how to fix it. Error: Column count doesn't match value count at row 1 <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $adduser = clean($_GET['user1']); $email = clean($_GET['email']); $IP = clean($_GET['ip']); if($username == '') { $errmsg_arr[] = 'username is missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD is missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated."; } ?> Here's the name of the columns i have got in my database: Code: [Select] username IP I have input the correct columns names, so I can't correct the problem I am getting. Please can you help? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331562.0 Why am I getting this error when there are 3 Fields with 3 values? Column count doesn't match value count at row 1 Code: [Select] $sql5="INSERT INTO participants (participant_name, team_no, sport) VALUES ('".implode("','$_POST[team]'),('",$_POST['participant_name'])."','$_POST[team]','$sport')"; Anyone can help me? <?php $tbl_name="menu"; $kategorije = mysql_query("SELECT * FROM $tbl_name WHERE Left(menu_name, 1) BETWEEN 'A' AND 'M' ORDER BY menu_name ASC"); if (!$kategorije) { die("Database query failed: " . mysql_error()); } while ($row=mysql_fetch_array( $kategorije )) { echo "<div id=lista-header><h4>{$row["menu_name"]}</h4></div>"; $id_sub=$row['id_menu']; $podkategorije = mysql_query("SELECT * FROM submenu WHERE id_menu=$id_sub ORDER BY sub_name ASC", $connection); if (!$podkategorije) { die("Database query failed: " . mysql_error()); } echo "<ul class=\"pod\">"; while ($pod=mysql_fetch_array( $podkategorije )) { echo "<li><a href=index.php?=podkate?".$pod["id_sub"]." class=black>{$pod["sub_name"]}</a><hr size=1 align=left width=100px color=#cccccc></li>"; } echo "</ul>"; } ?> In this way, I get list with categories and hes subcategories. How to count how many subcategories have each categories, and count how many articles have each categories? Example (I wanna get this kind of look): Categories name (3) subcategoriesname (2) subcategoriesname (4) subcategoriesname (7) Categories name (5) subcategoriesname (1) subcategoriesname (14) subcategoriesname (9) subcategoriesname (2) subcategoriesname ( Categories name (2) subcategoriesname (28) subcategoriesname (17) Where the numbers represent how many categories and sub-items have articles $epocTime = $math.newInt($math.divide("$today.getTime()", "1000"))) 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!
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 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? 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"); 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! 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 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 have a table in which I am storing a date/time value. It is stored as timestamp. When I try to echo the value, it does not return anything, just a blank field. this is my code (which works for the rest of my form - with non date values) anyone know why it is not working? Code: [Select] $arrival_time = $_GET['arrival_time']; Code: [Select] <tr> <td align="right" >Arrival Time</td> <td align="left"><input type="text" id="arrival_time_e" name="arrival_time_e" class="input" value="<?php if (!empty($arrival_time)) echo $arrival_time;?>" /></td> </tr> i hava also tried ... which returns the value of 1969-12-31 19:00 (but the dates stored in my database are the right timestamp format, 2011-04-26 22:43:11) Code: [Select] <tr> <td align="right" >Arrival Time </td> <td align="left"><input type="text" id="arrival_time_e" name="arrival_time_e" class="input" value="<?php echo date("Y-m-d H:i ", strtotime($row['arrival_time']));?>" /> </td> </tr hope someone can help 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! 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()); 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. 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?
|