Format A Raw Date
Moderator: General Moderators
Format A Raw Date
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.
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
Its rather simple and does not require PHP use a html select element
Example
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
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> 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
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
Example: It woukld determine it is March, so it would print out 01-31
Last edited by icesolid on Tue Mar 11, 2008 10:14 am, edited 2 times in total.
Re: Format A Raw Date
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
Sorry that is not what I am looking for.
Re: Format A Raw Date
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?
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?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Format A Raw Date
I have solved that problem. Now I am wondering how to do this:
How can I determine the number of days in a month?
How can I determine the number of days in a month?
Re: Format A Raw Date
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)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Format A Raw Date
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.
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.