Hi everubody,
I have a timestamp field in a mysql DB and I want to know how much time
has past since that timestamp.
is it possible?
Say that I have this value in a variable -
1) how do I get the current system timestamp?
2) how do I subtract the first from the second?
Thanks! 8 1832
Super Mango wrote: Say that I have this value in a variable - 1) how do I get the current system timestamp? 2) how do I subtract the first from the second?
If you are only interested in the amount of hours, you could do something
like:
$now = time();
$past = time() - 86400;
print 'The difference between $past and $now = ';
echo ($now - $past) / 3600, ' hours';
Of course, you can narrow this figure down to days (div 86400), hours (div
3600), minutes (div 60) and seconds.
These kind of calculations can also be performed by MySQL. Have a look at
the manual @ mysql.com for more info.
JW
thanks!
But the thing is that the value in the DB is kept as YYYY-MM-DD hh:mm
how do I convert that to the "time()" format?
Super Mango wrote: Hi everubody,
I have a timestamp field in a mysql DB and I want to know how much time has past since that timestamp.
is it possible? Say that I have this value in a variable - 1) how do I get the current system timestamp? 2) how do I subtract the first from the second?
Thanks!
I can show you how to do it at a website down the wire using a bash
script. Should be adaptable to something local and PHP.
TIMESTAMP=$(dat e -d "`lynx -error_file=lynx _error -dump
-connect_timeout =20 $url/timestamp.txt`" +%s)
Super Mango wrote: thanks!
But the thing is that the value in the DB is kept as YYYY-MM-DD hh:mm how do I convert that to the "time()" format?
Per example, with strtotime: http://www.php.net/strtotime
JW
>I have a timestamp field in a mysql DB and I want to know how much time has past since that timestamp.
is it possible?
Yes. Use MySQL to do it.
Say that I have this value in a variable - 1) how do I get the current system timestamp?
now()
2) how do I subtract the first from the second?
timestampdiff() . (requires MySQL 5.0 or greater).
timediff(), but it returns the value in hours, minutes, and seconds.
datediff(), but only the date parts are used.
Gordon L. Burditt
Super Mango wrote: But the thing is that the value in the DB is kept as YYYY-MM-DD hh:mm how do I convert that to the "time()" format?
select UNIX_TIMESTAMP( column) from table;
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Super Mango wrote: I have a timestamp field in a mysql DB and I want to know how much time has past since that timestamp.
<?php
// Assume timestamp from database is in $ts.
$then = strtotime($ts);
$now = time();
$diff = $now - $then;
// $diff is the difference in seconds.
?>
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
"Super Mango" <li********@gma il.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. . Hi everubody,
I have a timestamp field in a mysql DB and I want to know how much time has past since that timestamp.
is it possible? Say that I have this value in a variable - 1) how do I get the current system timestamp? 2) how do I subtract the first from the second?
Thanks!
If you're going to be doing the vast majority of your time maths outside
MySQL, you might want to use integers instead of timestamps - you can just
save the unix timestamp in the database, which saves time converting between
MySQL and unix times. And, of course, you can still search/sort using the
unix timestamp... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: perplexed |
last post by:
How do you convert a user inputted date to a unix timestamp before
insterting it into your database? I have a form, with a textfield for
a date that the user inputs in the format mm-dd-yyyy and three dropdow
boxes for hours, minutes, and AM/PM. All of these need to be considered
together and converted to one Unix Timestamp and then inserted to the
MYSQL date field. The type of field is INT (11) so that I can instead
of the standard...
|
by: Terence |
last post by:
I need some clarification with pointer arithmetics on void *.
Example 1:
========
char s;
char *ptr = s;
ptr += 1;
// I assume ptr is increased by 1 byte, pointing to the 2nd element in the array, right?
Example 2:
|
by: Milan Èermák |
last post by:
Hi all,
I'm about to write an arithmetics object library. It should contain
classes like ShortInteger (for 32-bit longs), Double and Float as
standard numeric type wrappers and LongInteger (really long numbers, not
only 64-bit) and Fraction (to express high precission).
All these classes may inherit from abstract class Number.
I got stuck on following point. I'm not sure how to implement basic
arithmetic operations. What the result type...
|
by: Jonas Ernst |
last post by:
Hi,
Can somebody give me some hints how to do a line interpolation without using
floating point arithemtics?
The function shall do a linear interpolation between 2 points (line interp?)
and it shall return the y value to any x value given.
e.g. p1: (0,0)
p2 (1000,50)
y value to calculate at x=600
|
by: Rein Anders Apeland |
last post by:
Hi all,
We are developing a PoS application for Linux and are in need of a LGPL'ed
og other 'free'-licensed library
that can do exact decimal arithmetics for us.
It should be similar or according to the specs at
http://www2.hursley.ibm.com/decimal/
Somebody pointed my to the GNU Multiple Precision library, but that still
| |
by: rong.guo |
last post by:
Hello Group,
I am having a really weird problem... Can anyone tell the difference
between Query 1 and Query 2 below? Why Query 2 excludes '2/28/2005'?
Many thanks!
create table a
(ApplicationID int
,timestamp datetime)
|
by: Russell Smith |
last post by:
Timestamps support infinity. However if appears dates do not.
When timestamps are cast to dates, there is no output. Is this an acceptable option or not?
Below are a number of examples showing what I am experiencing.
The last own shows how converting timestamps to dates and then ordering doesn't give you the
order you want. Maybe you should just order by the timestamp to begin with. However
Date does not understand infinity at all.
|
by: Mal Ball |
last post by:
I hope I have the right forum for this question. I have an existing Windows
application which uses a SQL Server database and stored procedures. I am now
developing a web application to use the same database.
The original Update and Delete SP's all use a timestamp for concurreny
checking.
I am trying to use the same Update SP from my sqlDataSource but I keep
getting the following error:
|
by: JJ |
last post by:
How do I set one field to have the updated timestamp, and another to have
the created timestamp?
I want to do this directly from code generated from DB Designer if
possible?!
JJ
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |