Results 1 to 2 of 2

Thread: Concatenate Dates

  1. #1
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Concatenate Dates

    I currently have 3 columns: month, day, year. I would like to concatenate them in the WHERE clause like this:
    CONCAT_WS('-', event.`year`, event.`month`, event.`day`) >= CURDATE()

    so that I show only upcoming dates. the problem is, however, that if the month and day are single digits, there is no zero in front of them. so the string is coming out as

    2009-4-5 >= 2009-04-05

    Is there a way to add zeros to the single digits in the table itself or in the clause? When I try adding it in the table, it just deletes it. They are currently integers. I could make it a VARCHAR, but then it also depends on if the user enters it right. Is this even the best way to go about it? Thank you for your suggestions.

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Hi

    Sorry if this is a bit late and you have already sorted this problem out.

    What I do to get the leading zeroes is to add 100 to each number and then use a string function to take the last 2 characters.

    ie
    $day1 = $day + 100
    $day2=substr($day1,1,2)

Bookmarks

Posting Permissions

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