Solved

PHP: compare (<) two times given in MySQL text format

Posted on 2011-02-23
3
373 Views
Last Modified: 2012-06-21
I have echoed the two times (as an example) of a comparison i'm trying to do:

2011-02-22 16:42:05  <  2011-02-22 16:38:11

I've tried:  comparing the two text strings directly(!);   strcmp();   and  strtotime < strtotime

how is the best way to do this successfully?   (the strlen is always the same)

thanks
0
Comment
Question by:willsherwood
3 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
ID: 34963663
Just compare them directly like you are doing.
0
 

Author Comment

by:willsherwood
ID: 34963717
thanks, i retried, more confidently this time, and it worked.
(something else was amiss and i was blaming it on the  <  comparison!)

appreciated
0
 
LVL 17

Expert Comment

by:Dushan911
ID: 34963792
$date1='2011-02-22 16:42:05';
$date2='2011-02-22 16:38:11';

if(strtotime($date1)  <  strtotime($date2))
{
    echo "ok";
}
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now