Solved

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

Posted on 2011-02-23
3
389 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
[X]
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
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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The viewer will learn how to count occurrences of each item in an array.
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…

724 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