473,397 Members | 1,972 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,397 software developers and data experts.

converting date to minutes

OK, I have $x="200504161035"
that is 10:35 on 16 April 2005.

My questuion: what is the *shortest* piece of code to convert that variable
to minutes? I have a feeling there is a PHP function that should be able to
do it but I cannot find it. The long way takes 5 lines of code.

Regards
John
Jul 17 '05 #1
3 1819
Justice wrote:
OK, I have $x="200504161035"
that is 10:35 on 16 April 2005.


In minutes compared to what? The difference between that date and now?
JW

Jul 17 '05 #2
Janwillem Borleffs wrote:
In minutes compared to what? The difference between that date and now?


When that's your objective, you could do something like the following:

$ts = "200504161035";
$ts = strtotime(substr($ts, 0, 8) . " " . substr($ts, -4));
$minutes = round(($ts - time()) / 60);

Of course, you should substract $ts from time() when $ts is in the past.
JW

Jul 17 '05 #3
Thanks.
The function that had escaped me was STRTOTIME which I could have used on
the date part only.
Many thanks. 2 lines of code is ideal.
Regards
John
"Janwillem Borleffs" <jw@jwscripts.com> wrote in message
news:42***********************@news.euronet.nl...
Janwillem Borleffs wrote:
In minutes compared to what? The difference between that date and now?


When that's your objective, you could do something like the following:

$ts = "200504161035";
$ts = strtotime(substr($ts, 0, 8) . " " . substr($ts, -4));
$minutes = round(($ts - time()) / 60);

Of course, you should substract $ts from time() when $ts is in the past.
JW

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Frank | last post by:
I am timing employees who take a test. I have the start time and end time, which are unix epochs, and subtracing the start from the end will give me a large number of seconds, for example 552. I...
1
by: renee_ld | last post by:
In a query I used the function datediff to calculate the number of minutes between two time periods on a given day. This function returned the number of minutes as a long integer data type. I...
6
by: Mark Reed | last post by:
Hi Guru's, I have created a database to monitor hours I have worked as our payroll department are so crap. I work nights most of the time but occasionally I have to work on days. Between the hours...
7
by: Stu | last post by:
Is there a simple function call within "C" that I can use to convert number of seconds (keep in mind this may be a type longlong and has to work on UNIX and NT) into Days, months, Hours, Minutes...
2
by: x | last post by:
hi i am a pilot by profession. i want to create a database of my logbook using ms access 2002. i am facing a problem regarding the format of time field. when i select "Data/Time" data type for my...
32
by: robert d via AccessMonster.com | last post by:
I'm looking at converting DAO to ADO in my app. All of my DAO connections are of the following structure: Dim wsName As DAO.Workspace Dim dbName As DAO.Database Dim rsName As DAO.Recordset ...
2
by: mar10 | last post by:
i have TIME WORKED stored as minutes - I'd like to convert this to days,hours,minutes. I'm currently converting to hours and minutes but have not had success adding the days portion to the...
5
by: =?Utf-8?B?emlubw==?= | last post by:
I need to convert a string as: "DEC 18 2007 2:49:40:783PM" to a date. This value is sent by SQL server as :select convert(varchar(30), creationDate, 109) from ... ... . I tried : Dim dt As...
3
by: mulchgirl | last post by:
I have a table where I have fields name START DATE and SHUT OFF DATE with the data type at Date/Time and it's format set to General Date so that I can record both date and time of starting and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.