Jump to content

Distinguish time between night and day


adzie

Recommended Posts

Hello folks  :)

 

Before I embark on a small project I'd appreciate as always any tips on problems I might encounter or suggestions on how best to acheive the end result.

 

My table holds multiple records for each user, it contains the stamp of when they logged in and the duration.

 

Records Table

id userid stamp duration activity

 

1

admin1

2009-08-09 16:45:00

02:00:06

IMC

 

Currently I display to a webpage each row as is.  What I'd like to do is split it up and show either day or night.

 

If a user logs on in the above example I'd like to show the time up until 1800 as day and after 1801 as night.  The user will have multiple entries so i'd like to display each entry as a row but just splitting out night and day time.

 

 

Date Activity Day hrs Night Hrs

 

09-08-2009  IMC 01:15:00  00:45:00

 

Any tips appreciated

 

 

Link to comment
https://forums.phpfreaks.com/topic/172144-distinguish-time-between-night-and-day/
Share on other sites

you could do this different ways. in mysql you can query the datetime field like so:

 

SELECT TIME(timestamp) as time...

 

which extracts the time part of that field for you to process, or you could parse your timestamp with PHP. I don't know much about regex or eregi, but I do know every date in your column will be of the form '2009-08-09 16:45:00' so you can explode that string at the space character. then do your calculations.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.