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

Times

Hi,

I'm currently storing start and end times (hh:mm:ss) for shows in a
radio schedule using MySQL and processing the data with PHP.

I need to add one second to the end time to ensure it is formatted
correctly (e.g. 09:29:59 to 9:30am) however I just cannot see how to do
it *correctly* - with PHP or MySQL. I may well be overlooking something
but I would be grateful if anybody could help and point me in the right
direction.

Thanks in advance.

Cheers,
Matt
Jul 17 '05 #1
7 1463
I noticed that Message-ID:
<uA*****************@text.news.blueyonder.co.uk> from Matthew Bates
contained the following:
I need to add one second to the end time to ensure it is formatted
correctly (e.g. 09:29:59 to 9:30am) however I just cannot see how to do
it *correctly* - with PHP or MySQL. I may well be overlooking something
but I would be grateful if anybody could help and point me in the right
direction.

If you are storing this as a date, get a UNIX timestamp, add the second,
and format using PHP.

$sql="SELECT *, UNIX_TIMESTAMP($datefield) AS unixdate FROM `table`
";
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2
Geoff Berrow wrote:
I noticed that Message-ID:
<uA*****************@text.news.blueyonder.co.uk> from Matthew Bates
contained the following:

I need to add one second to the end time to ensure it is formatted
correctly (e.g. 09:29:59 to 9:30am) however I just cannot see how to do
it *correctly* - with PHP or MySQL. I may well be overlooking something
but I would be grateful if anybody could help and point me in the right
direction.


If you are storing this as a date, get a UNIX timestamp, add the second,
and format using PHP.

$sql="SELECT *, UNIX_TIMESTAMP($datefield) AS unixdate FROM `table`
";


Thanks for your quick reply.

I'm storing them as times, as they relate to any weekday/weekend day
rather than a specific date.

Matt
Jul 17 '05 #3
I noticed that Message-ID:
<6J******************@text.news.blueyonder.co.uk > from Matthew Bates
contained the following:

$sql="SELECT *, UNIX_TIMESTAMP($datefield) AS unixdate FROM `table`
";


Thanks for your quick reply.

I'm storing them as times, as they relate to any weekday/weekend day
rather than a specific date.


I've not tried it, but it will probably work.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4
On Sat, 25 Jun 2005 22:07:22 GMT, Matthew Bates <ma********@hotmail.com> wrote:
I'm currently storing start and end times (hh:mm:ss) for shows in a
radio schedule using MySQL and processing the data with PHP.

I need to add one second to the end time to ensure it is formatted
correctly (e.g. 09:29:59 to 9:30am) however I just cannot see how to do
it *correctly* - with PHP or MySQL. I may well be overlooking something
but I would be grateful if anybody could help and point me in the right
direction.


mysql> select d, d + INTERVAL 1 SECOND from t;
+---------------------+-----------------------+
| d | d + INTERVAL 1 SECOND |
+---------------------+-----------------------+
| 2005-06-25 09:29:59 | 2005-06-25 09:30:00 |
+---------------------+-----------------------+
1 row in set (0.00 sec)

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5
Andy Hassall wrote:
On Sat, 25 Jun 2005 22:07:22 GMT, Matthew Bates <ma********@hotmail.com> wrote:

I'm currently storing start and end times (hh:mm:ss) for shows in a
radio schedule using MySQL and processing the data with PHP.

I need to add one second to the end time to ensure it is formatted
correctly (e.g. 09:29:59 to 9:30am) however I just cannot see how to do
it *correctly* - with PHP or MySQL. I may well be overlooking something
but I would be grateful if anybody could help and point me in the right
direction.

mysql> select d, d + INTERVAL 1 SECOND from t;
+---------------------+-----------------------+
| d | d + INTERVAL 1 SECOND |
+---------------------+-----------------------+
| 2005-06-25 09:29:59 | 2005-06-25 09:30:00 |
+---------------------+-----------------------+
1 row in set (0.00 sec)


I thought that was the case however I'm not storing dates, I'm storing
times as the times can relate to any weekday/weekend day (e.g. 9:30:00
on a Saturday is programme x, 10:30:00 is programme y..).
Jul 17 '05 #6
On Sat, 25 Jun 2005 23:06:23 GMT, Matthew Bates <ma********@hotmail.com> wrote:
Andy Hassall wrote:
On Sat, 25 Jun 2005 22:07:22 GMT, Matthew Bates <ma********@hotmail.com> wrote:
I'm currently storing start and end times (hh:mm:ss) for shows in a
radio schedule using MySQL and processing the data with PHP.

I need to add one second to the end time to ensure it is formatted
correctly (e.g. 09:29:59 to 9:30am)

[snip]
I thought that was the case however I'm not storing dates, I'm storing
times as the times can relate to any weekday/weekend day (e.g. 9:30:00
on a Saturday is programme x, 10:30:00 is programme y..).


mysql> create table t (t time);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t values ('000000');
Query OK, 1 row affected (0.00 sec)

mysql> insert into t values ('000001');
Query OK, 1 row affected (0.00 sec)

mysql> insert into t values ('092959');
Query OK, 1 row affected (0.00 sec)

mysql> insert into t values ('235959');
Query OK, 1 row affected (0.00 sec)

mysql> select t, addtime(t, '000001') from t;
+----------+----------------------+
| t | addtime(t, '000001') |
+----------+----------------------+
| 00:00:00 | 00:00:01 |
| 00:00:01 | 00:00:02 |
| 09:29:59 | 09:30:00 |
| 23:59:59 | 24:00:00 |
+----------+----------------------+
4 rows in set (0.04 sec)

Don't like the 24:00:00? Then how about:

mysql> select sec_to_time(mod(time_to_sec(t)+1,86400)) from t;
+------------------------------------------+
| sec_to_time(mod(time_to_sec(t)+1,86400)) |
+------------------------------------------+
| 00:00:01 |
| 00:00:02 |
| 09:30:00 |
| 00:00:00 |
+------------------------------------------+
4 rows in set (0.03 sec)

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #7
Andy Hassall wrote:
On Sat, 25 Jun 2005 23:06:23 GMT, Matthew Bates <ma********@hotmail.com> wrote:

Andy Hassall wrote:
On Sat, 25 Jun 2005 22:07:22 GMT, Matthew Bates <ma********@hotmail.com> wrote:
I'm currently storing start and end times (hh:mm:ss) for shows in a
radio schedule using MySQL and processing the data with PHP.

I need to add one second to the end time to ensure it is formatted
correctly (e.g. 09:29:59 to 9:30am)

[snip]
I thought that was the case however I'm not storing dates, I'm storing
times as the times can relate to any weekday/weekend day (e.g. 9:30:00
on a Saturday is programme x, 10:30:00 is programme y..).

mysql> create table t (t time);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t values ('000000');
Query OK, 1 row affected (0.00 sec)

mysql> insert into t values ('000001');
Query OK, 1 row affected (0.00 sec)

mysql> insert into t values ('092959');
Query OK, 1 row affected (0.00 sec)

mysql> insert into t values ('235959');
Query OK, 1 row affected (0.00 sec)

mysql> select t, addtime(t, '000001') from t;
+----------+----------------------+
| t | addtime(t, '000001') |
+----------+----------------------+
| 00:00:00 | 00:00:01 |
| 00:00:01 | 00:00:02 |
| 09:29:59 | 09:30:00 |
| 23:59:59 | 24:00:00 |
+----------+----------------------+
4 rows in set (0.04 sec)

Don't like the 24:00:00? Then how about:

mysql> select sec_to_time(mod(time_to_sec(t)+1,86400)) from t;
+------------------------------------------+
| sec_to_time(mod(time_to_sec(t)+1,86400)) |
+------------------------------------------+
| 00:00:01 |
| 00:00:02 |
| 09:30:00 |
| 00:00:00 |
+------------------------------------------+
4 rows in set (0.03 sec)


Superb! The addtime function was exactly what I needed - thank you :).

Matt
Jul 17 '05 #8

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

Similar topics

5
by: Mark Fisher | last post by:
I have a Java desktop GUI application that the user can run multiple times. In order to keep one instance of the application distinct from another, I'd like to put the instance number of the...
6
by: Christian | last post by:
HI, I have a function that is used to constrain a query: Select COl1, Col2 From MyTable WHERE col1 = ... AND col2 = ... And MyFunction(col1) = ... My problem is that MyFunction is executed...
1
by: Anthony | last post by:
Here is a debate we have been having at work about the design of our timeclock database application. We have built an online timeclock system for companies to use to keep track of their employees...
10
by: Sunny K | last post by:
Hi guys, I have a field in my DB called EventDate as a DateTime field, therefore it holds both the date and time together like this: '2004-10-14 08:42:57.000'. I need to add together all the...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
14
by: Steve McLellan | last post by:
Hi, Sorry to repost, but this is becoming aggravating, and causing me a lot of wasted time. I've got a reasonably large mixed C++ project, and after a number of builds (but not a constant...
87
by: John Rivers | last post by:
Hello everybody, I just wondered if anybody else has noticed this? It takes around 6 seconds to start debugging a very simple ASPX page with VS.NET whereas VB6 takes under 0.5 seconds, even...
4
by: viuxrluxvbbc | last post by:
Hi im trying to write a program that will read in numbers and display them in ascending order along with a count of how many times it repeats. i got the numerical order portion done but cant figure...
4
by: kwatch | last post by:
Hi, I have a question about os.times(). os.times() returns a tuple containing user time and system time, but it is not matched to the result of 'time' command. For example, os.times() reports...
2
by: hari | last post by:
Hi all, suppose a hex value is there(say 3B), this needs to be expanded. Suppose if this 3B(0011 1011) needs to be expanded by 3 times, then each bit should be expanded by 3 times(000000111111...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
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...

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.