Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Date format issue

    Hi, well my boss said the format for the date in our database is mm/dd/yyyy and when i get the current_date() to compare the two I have the problem of them being different

    current_date() is yyyy-mm-dd (right?)
    event_startDate is mm-dd-yyyy

    I tried using the get_format() function to get them to be the same but it doesnt seem to be working correctly.

    What I am trying to do is write a query that gets the information for the next upcoming meeting. Thus, the events_startDates needs to be greater than the current_date() and i merely grab the "closest" meeting or the first row as it were.

    This is what i have so far. How do I get the dates to be comparable to each other?

    $query = mysql_query("SELECT * FROM meeting_list, events WHERE event_startDate > current_date() AND eventID = ID AND event_type != 'Sales' ORDER BY event_dates ASC LIMIT 1");

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You should always store dates using a data type of "date". Find out if this is the case.

    If your event_startDate is being stored as a string, you'll need to use the str_to_date() function on it to transform it into a date before you can use comparison operators on it.

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol...yeah he just got off the phone and told me it is a string. He thinks the best way to handle this is to split the string up and compare each part.

    personally, I dont know what would be best or easiest but whatever i choose it is only temporary. He plans on changing the column to date soon.

    bah, this is silly

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Splitting up the string and comparing each part would be the absolute worst way to do it... try str_to_date() first.

  • #5
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    See the link in my signature about varchar dates.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •