Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP: Between Two Times

PHP: Between Two Times
Thread Tools
sandsl
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status: Offline
Reply With Quote
May 14, 2005, 07:04 PM
 
Hi,

In PHP, I have two times (eg. 2215) and (eg. 0020), how do you find out whether a third time (eg. 2316) is between this period?

I've tried different combinations of using date() and mktime() but I can't quite get it working. Any help would be much appreciated.

Thanks,
Luke
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
May 14, 2005, 08:45 PM
 
Aren't times comparable in PHP (i.e. with the greater-than and less-than operators)? I'm not a huge PHPer these days, but I thought that worked.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
ctlq
Junior Member
Join Date: Nov 2004
Location: Michigan
Status: Offline
Reply With Quote
May 15, 2005, 01:24 AM
 
I deal w/ things that use this alot (unfortunately) and the easiest solution is this:
start1 <= end2 && start2 <= end1

So in your example you could do:
if ( 0020 <= 2316 && 2316 <= 2215) {}

if you've got an actual date & time convert it to unix timestamp and then compare.

This is a language independent way, if someone's got an easier way w/ php I'd love to hear it.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:31 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,