Page 1 of 1
Format A Raw Date
Posted: Tue Mar 11, 2008 9:04 am
by icesolid
I have a field called 'due_date'. When the user types their date in that box I have five characters available for input. I am looking for mm-dd format to be inputted. However, the user doesn’t always submit it that way. How can I reformat that 'due_date' so into an mm-dd format no matter how it is submitted? I do not use the year in this.
I do not want to use a selection box for this because the range of dates that would be submitted here is very large. I do not want people to have to scroll through some large list of dates.
Re: Format A Raw Date
Posted: Tue Mar 11, 2008 9:20 am
by anto91
Its rather simple and does not require PHP use a html select element
Example
Code: Select all
<select name="month"> <option value="1">January</option> <!-- and continue --></select><select name="day"> <option value="1">1</option> <!-- and continue --></select>
You might want to add a simple javascript to add 1 or remove one day depending on the month but i find this a simple solution that is always valid, unless the user creates there own form and sends directly to you :=)
Edit: oh sorry didnt read the lastbit >.< my fault
Solution 2:
use a regex expression and if its not valid create your own date of the current day
I would give an example but i dont know regex
Re: Format A Raw Date
Posted: Tue Mar 11, 2008 9:45 am
by icesolid
How can I determine the number of days in a month and then print them all out including the traling zeros.
Example: It woukld determine it is March, so it would print out 01-31
Re: Format A Raw Date
Posted: Tue Mar 11, 2008 10:12 am
by anto91
there is probaly a better way but you could use this
Code: Select all
<?php
$day = 2;
if($day <= 9) {
$day = '0'.$day;
}
?>
Re: Format A Raw Date
Posted: Tue Mar 11, 2008 10:15 am
by icesolid
Sorry that is not what I am looking for.
Re: Format A Raw Date
Posted: Tue Mar 11, 2008 11:47 am
by pickle
If you don't mind requiring javascript, use a Javascript date picker.
Or have 2 different fields - one for the month & one for the day. It'd be pretty easy to check that both of them are integers. As to whether it's a valid day of the month, date() has the ability to check how many days are in a given month (but you must provide a year) - which raises another question. What are you going to do about Feb 29?
Re: Format A Raw Date
Posted: Tue Mar 11, 2008 11:50 am
by icesolid
I have solved that problem. Now I am wondering how to do this:
How can I determine the number of days in a month?
Re: Format A Raw Date
Posted: Tue Mar 11, 2008 12:04 pm
by pickle
I believe that's already been covered:
pickle wrote:As to whether it's a valid day of the month, date() has the ability to check how many days are in a given month (but you must provide a year)
Re: Format A Raw Date
Posted: Tue Mar 11, 2008 12:13 pm
by icesolid
OK I want to know how many days are in the month of March 2008.
I don't see where he covered that. He talked about if I wasn’t using the year, but I have solved that problem, I am using the year now. So I will know that it is 2008 or 2009 or whatever the current year is.