Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to check if a datetime from mysql is the same Date as another?

  1. #1
    Member
    Join Date
    Jan 2011
    Posts
    78
    My Mood
    Confused
    Thanks
    23
    Thanked 1 Time in 1 Post

    Default How to check if a datetime from mysql is the same Date as another?

    I am trying to use this function:

    these variables are stored in datetime format of mysql.
    var1:2012-02-01 01:39:32
    var2:2012-02-02 01:47:11

    PHP Code:
    if (date('Ymd'$var1) == date('Ymd'$var2)
    {
    //True


    Why does this output true every time?

    Any other suggestions on how to do this? Please keep in mind I'm limited to doing this in PHP on this page without using any database. And I'm looking only for the same date not a 24Hour difference, however I don't care about differences in time zones as long as both variables reflect the same timezone.
    Last edited by Hallowed; February 2nd, 2012 at 02:28 PM.


  2. #2
    Member
    Join Date
    Dec 2011
    Posts
    50
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: How to check if a datetime from mysql is the same Date as another?

    It is always true because it does not compare the time part, only the date part. You need to use different pattern that includes the time part also.
    Or better you can compare the milliseconds from the two dates.

  3. #3
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: How to check if a datetime from mysql is the same Date as another?

    I was going to suggest you should ask this question on a PHP forum, but then I would have to not answer it

    PHP: date - Manual

    ... says the argument is a Unix timestamp - not a MySQL datetime. What do you get if you echo the expressions either side of the '=='?

Similar Threads

  1. How to check for empty mysql table
    By A4Andy in forum Java Theory & Questions
    Replies: 1
    Last Post: August 27th, 2011, 12:43 AM
  2. Replies: 1
    Last Post: July 22nd, 2011, 08:08 AM
  3. same date should entered in another date field
    By shashib09 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: July 14th, 2011, 09:42 AM
  4. DateTime Convertion To Binary
    By Aamir in forum Java Networking
    Replies: 3
    Last Post: May 12th, 2011, 10:40 AM
  5. how to check the value
    By javaking in forum Java Servlet
    Replies: 2
    Last Post: July 22nd, 2010, 07:56 AM