PHP - Date / Timestamp
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 Similar TutorialsHi guys, I'm putting together a small event system where I want the user to add his own date and time into a textfield (I'll probably make this a series of drop-downs/a date picker later). This is then stored as a timestamp - "0000-00-00 00:00:00" which displays fine until I try to echo it out as a UK date in this format - jS F Y, which just gives today's date but not the inputted date. Here's the code I have right now: Code: [Select] $result = mysql_query("SELECT * FROM stuff.events ORDER BY eventdate ASC"); echo "<br />"; echo mysql_result($result, $i, 'eventvenue'); echo ", "; $dt = new DateTime($eventdate); echo $dt->format("jS F Y"); In my mysql table eventdate is set up as follows: field - eventdate type - timestamp length/values - blank default - current_timestamp collation - blank attributes - on update CURRENT_TIMESTAMP null - blank auto_increment - blank Any help as to why this could be happening would be much appreciated, thanks. 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. 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>'; } }?> I want to convert a unix time stamp to the date format (dd/mm/yy). How can i be possible ? I'm having a weird issue going on, I'm wondering if it has to do with my php.ini or server setup, anyway here is the code with the odly outcomes: Code: [Select] echo date('Y/m/d H:i:s', 2145000000); // 2037/12/21 01:20:00 echo date('Y/m/d H:i:s', 2149000000); // 1901/12/31 01:58:24 echo date('Y/m/d H:i:s', 2150000000); // 1902/01/11 15:45:04 It seems after year 2037 it goes down to 1900+... Why would this happen? I've tried on 2 godaddy servers and local host and all same result 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 have a simple mysql database holding information about an image upload including its 'name' and 'date uploaded' [current_timestamp()] to a folder 'image' I then display it into a table using the php ‘foreach’ facility. I want the date to be displayed in the ‘dd/mm/yyyy’ format. not the default yyyy/mm/dd. Here is the relevant code <?php $conn = mysqli_connect("localhost", "root", "", "dbname"); $results = mysqli_query($conn, "SELECT * FROM tablename"); $image = mysqli_fetch_all($results, MYSQLI_ASSOC); ?> <?php foreach ($image as $user): ?> <td><p>NAME</p><?php echo $user['name']; ?></td> <td><p>COMMENT</p><?php echo $user['comment']; ?></td> <td><p>DATE</p><?php echo $user['date']; ?></td> What do I need to do? THANKS- Warren Following on from my problem with another Google Chart which jay0316 kindly helped with, I have another issue which I am hoping that someone might be able to help me with.
I am trying to put together a site for my wife to manage her diabetes and insulin intake. We want to monitor her blood/sugar glucose over periods of time (but with notes that she includes that can help monitor reasons for outlying results such as illness), so I am trying to include a Google Annotation Chart to do this, drawing on blood/glucose readings stored in a Database.
Where I am struggling at the moment is converting timestamps into information that I can include in the chart.
What I currently have at the moment (which obviously isn't working) is:
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['annotationchart']}]}"></script> <script type='text/javascript'> google.load('visualization', '1', {'packages':['annotationchart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('datetime', 'Date'); data.addColumn('number', 'Readings'); data.addColumn('string', 'Notes'); data.addRows([ <?php$annotate=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0"); Hey, I'm using a script which allows you to click on a calendar to select the date to submit to the database. The date is submitted like this: 2014-02-08 Is there a really simple way to prevent rows showing if the date is in the past? Something like this: if($currentdate < 2014-02-08 || $currentdate == 2014-02-08) { } Thanks very much, Jack 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. $epocTime = $math.newInt($math.divide("$today.getTime()", "1000"))) 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!
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? 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! 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! 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 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
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 |