Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2011-02-23
3
379 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:Dushan De Silva
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL Backup Strategy 15 44
parse url to form? 7 25
TCPDF - Create PDF from Form Values and Link to PDF Download 7 26
Wordpress Pagination 1 29
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…

860 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