473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Difference between two datestamps

384 256MB
I have a date being returned from a mysql database like so
2009-12-29 13:59:23
I'm trying to check to see how many hours and minutes the current time has progressed since the datetime stamp was updated.

So something like:
Expand|Select|Wrap|Line Numbers
  1. print date("Y-m-d G:H:s") - '2009-12-29 13:59:23';
This always returns zero, any help much appreciated.
Dec 29 '09 #1
2 1513
code green
1,726 Expert 1GB
date() returns a string so don't expect php to perform reliable arithmetic

This problems strikes me as better handled in MySQL using NOW() and TIMEDIFF()
Expand|Select|Wrap|Line Numbers
  1. SELECT TIMEDIFF(NOW() - `mydatefield`)
which I think returns the result in HH:MM:SS.ssss.
If it must be php then you will need timestamp arithmetic
Expand|Select|Wrap|Line Numbers
  1. time()-strtotime('my date value')
returning result in seconds
Dec 29 '09 #2
ziycon
384 256MB
Got what I wanted working using:
Expand|Select|Wrap|Line Numbers
  1. round((strtotime(date("Y-m-d G:H:s")) - strtotime($row['date']))/60 / 60)
Gives me a rough time line to work off which will do for what I need it. Thanks for your help.
Dec 29 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

34
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. ...
21
by: b83503104 | last post by:
Hi, Can someone tell me the difference between single quote and double quote? Thanks
26
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: ...
21
by: Rich | last post by:
I was considering C# for developing a scientific application, but I have noticed a ~30% difference between VC++ .NET and C# on the same machine, under identical conditions: double a = 0,b = 0, c...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
3
by: bbawa1 | last post by:
Hi, I have a table which has a field ItemsReceived of type datetime. I have a grid view which has two columns. In first column i have to show the data from field ItemsReceived and in second...
12
by: Petronius | last post by:
Hallo, does anyone have an idea how to implement difference lists in Javascript? Thanks allot in advance
5
by: Julius | last post by:
Hej dudes, I need to calc the difference between two timestamps / dates ... For example what i need to calculate: Date 1: 2007.11.06 - 20:13:04 Date 2: 2007.11.07 - 21:13:04 Difference:...
9
by: viki1967 | last post by:
Hi all! This new forum its great! :) Congratulations !!! My answer: why this my code not working? Nothing error but not work the difference.... : <html>
11
by: cmb3587 | last post by:
I have two arrays and I'm trying to create a 3rd array that is the difference between the two arrays Ex: arrayA: 3 5 8 9 arrayB: 3 4 6 9 difference of A-B: 5 8 however, my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.