By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,276 Members | 1,311 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,276 IT Pros & Developers. It's quick & easy.

Input string and date format

P: n/a
I've two input fields in wich the user enter dates.

I've put something like "enter date here (dd/mm/yyyy) but most of the user
don't enter date in correct format. So I'd like to be able to get any format
coming from user as I must put those dates in a MySQL database:
some format: (non-US format, so day/month/year)

1/9/2004
1/09/2004
01/9/2004
01/09/2004
1/9/04
1/09/04
01/9/04
01/09/04
same with any other separator like '-', space...
1-9-2004
1-09-04
1 10 2004
....
the max input field lenght is 10 characters.
I must put the entered value in a Mysql date field, so it must be well
formatted.

Does it exists any function ?

Bob
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Bob Bedford wrote:
Does it exists any function ?

* that automatically recognizes the date input format and reformats to
* another format?

Nope.

Try making your users enter dates bit-by-bit
Day: (dropdown list from 1 to 31)
Month: (dropdown list from January to December)
Year: (dropdown list from 1901 to <current_year>)

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #2

P: n/a
On 3 Dec 2004 15:35:30 GMT, Pedro Graca <he****@dodgeit.com> wrote:
Bob Bedford wrote:
Does it exists any function ?

* that automatically recognizes the date input format and reformats to
* another format?

Nope.

Try making your users enter dates bit-by-bit
Day: (dropdown list from 1 to 31)
Month: (dropdown list from January to December)
Year: (dropdown list from 1901 to <current_year>)


Which, unless you implement javascript or something similar, would
allow for such dates as 31 Feb, 2004
--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
DataBasix | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ۳
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Jul 17 '05 #3

P: n/a
"Gary L. Burnore" <gb******@databasix.com> a crit dans le message de news:
co**********@blackhelicopter.databasix.com...
On 3 Dec 2004 15:35:30 GMT, Pedro Graca <he****@dodgeit.com> wrote:
Bob Bedford wrote:
Does it exists any function ?

* that automatically recognizes the date input format and reformats to
* another format?

Nope.

Try making your users enter dates bit-by-bit
Day: (dropdown list from 1 to 31)
Month: (dropdown list from January to December)
Year: (dropdown list from 1901 to <current_year>)


Which, unless you implement javascript or something similar, would
allow for such dates as 31 Feb, 2004


I would have said I want absolutely avoid such entry type. I (and most
users) hate such entry type, also because all other fields close to them are
keyboard entries, I want to avoid the keyboard-mouse-keyboard-mouse fields
(even if people may use keyboard on dropdown, most don't know you can). it
must be keyboard entry.

Bob
Jul 17 '05 #4

P: n/a
Gary L Burnore wrote:
On 3 Dec 2004 15:35:30 GMT, Pedro Graca <he****@dodgeit.com> wrote:

Try making your users enter dates bit-by-bit
Day: (dropdown list from 1 to 31)
Month: (dropdown list from January to December)
Year: (dropdown list from 1901 to <current_year>)


Which, unless you implement javascript or something similar, would
allow for such dates as 31 Feb, 2004


Yes. Better than making the users submit year and month on one screen
and the day on the next screen.

Anyway:

php$ php -r cho date("Y-m-d", mktime(0, 0, 0, 2, 31, 2004));'
2004-03-02

If they try 31 Feb, 2004 they'll get 2 Mar, 2004 :-)
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #5

P: n/a
.oO(Bob Bedford)
I've put something like "enter date here (dd/mm/yyyy) but most of the user
don't enter date in correct format. So I'd like to be able to get any format
coming from user as I must put those dates in a MySQL database:
some format: (non-US format, so day/month/year)


If it's always d/m/y just with different separators it should be quite
easy to do with a regular expression, something like

$pattern = '#^(\d{1,2})[/-](\d{1,2})[/-](\d{1,2}|\d{4})$#';
preg_match($pattern, $date, $result);

After splitting use checkdate() to see if the entered date is valid.

Micha
Jul 17 '05 #6

P: n/a
.oO(Pedro Graca)
Try making your users enter dates bit-by-bit

Day: (dropdown list from 1 to 31)
Month: (dropdown list from January to December)
Year: (dropdown list from 1901 to <current_year>)


One of the worst things you can do in terms of usability.

Micha
Jul 17 '05 #7

P: n/a
Take a look at http://www.tonymarston.co.uk/php-mysql/dateclass.html

--
Tony Marston

http://www.tonymarston.net
"Bob Bedford" <be******@YouKnowWhatToDoHerehotmail.com> wrote in message
news:41**********************@news.sunrise.ch...
I've two input fields in wich the user enter dates.

I've put something like "enter date here (dd/mm/yyyy) but most of the user
don't enter date in correct format. So I'd like to be able to get any
format coming from user as I must put those dates in a MySQL database:
some format: (non-US format, so day/month/year)

1/9/2004
1/09/2004
01/9/2004
01/09/2004
1/9/04
1/09/04
01/9/04
01/09/04
same with any other separator like '-', space...
1-9-2004
1-09-04
1 10 2004
...
the max input field lenght is 10 characters.
I must put the entered value in a Mysql date field, so it must be well
formatted.

Does it exists any function ?

Bob

Jul 17 '05 #8

P: n/a
Hi Michael
$pattern = '#^(\d{1,2})[/-](\d{1,2})[/-](\d{1,2}|\d{4})$#';
preg_match($pattern, $date, $result);

I've to store the value in a MySQL database, so I've to get correct format.

Thanks for your help, Tony Marston gave an excellent tutorial and full code
for what I wanted to do.

Cheers.
Jul 17 '05 #9

P: n/a

"Tony Marston" <to**@NOSPAM.demon.co.uk> a crit dans le message de news:
co*******************@news.demon.co.uk...
Take a look at http://www.tonymarston.co.uk/php-mysql/dateclass.html

--
Tony Marston

http://www.tonymarston.net


Great, thanks for your help. I've bookmarked your site ;-)

Cheers
Jul 17 '05 #10

P: n/a
.oO(Bob Bedford)
$pattern = '#^(\d{1,2})[/-](\d{1,2})[/-](\d{1,2}|\d{4})$#';
preg_match($pattern, $date, $result);
I've to store the value in a MySQL database, so I've to get correct format.


Sure. The above code was just for splitting a submitted date. If you
have separate values for day, month and year it's a quite simple task to
check the date and to create a yyyy-mm-dd string.
Thanks for your help, Tony Marston gave an excellent tutorial and full code
for what I wanted to do.


OK.

Micha
Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.