-
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.
-
-
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)
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks