[SOLVED] date to time()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

date to time()

Post by ddragas »

Hi all!

I've got form in one page that posts value of date (written in textbox) to second page.

I've got two questions.
In what format should date be written in text box

date month year

month date year

month/date/year

or how

second question

how to convert that date to time()
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

1. If it's in english/language, it can be any of those I think. If it's numbers, you may need to fiddle around with it..
2. [php_man]strtotime[/php_man]
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I may be wrong, but I think the American standard is Month/Day/Year and the British (and Canadian and probably everywhere else) standard is Day/Month/Year.

I'd make each section it's own textbox. Then, you can easily use [php_man]mktime[/php_man]() to get your timestamp.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

If I write in textbox month/day/year it works.

How can I write it in day/month/year
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Post by litebearer »

not the prettiest, but by using php generated dropdowns for the month, date and year you sidestep any confusion and are easily able to redisplay in any format you choose.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

What's your setup? Do you have just a plain HTML textbox? If so, you could type anything you want in there, it's just a matter of how it is handled on the second page.
Your best bet is to convert whatever format you choose to timestamp as soon as possible, as it's much easier to handle and manipulate.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

i got around this problem by useing javascript....which wont work on some computer cos the whole 'javascript is evil' deal, but it was for admin area on a project, so its ok :P.

get a popup calendar script, such as

http://www.dynamicdrive.com/dynamicinde ... lendar.htm
http://www.dynamicdrive.com/dynamicinde ... endar2.htm

then make the textbox READ ONLY, so users cant type it in, they must select a date, simple eh :wink:.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

thank you for advice. I'll do that
Post Reply