Page 1 of 1
help getting today's date into form
Posted: Thu Aug 10, 2006 12:37 pm
by jmilane
Hi,
I have a form.
I need to return today's date in a hidden field.
I need the time stripped off of it - mysql format.
This is the field now:
<input value="0" type="hidden" id="qf_5d8d6e" name="custom_17" />
I need input value to be today's date, minus all the time stuff, and in a format mysql can take without choking.
I'd appreciate any help. I have tried a bunch of stuff, but none of it works.
J
Re: help getting today's date into form
Posted: Thu Aug 10, 2006 12:49 pm
by Christopher
Code: Select all
<input value="0" type="hidden" id="qf_5d8d6e" name="custom_17" value="<?php echo date('Y-m-d'); ?>" />
Check the date() function's manual page for different date formats.
Posted: Fri Aug 11, 2006 1:12 am
by RobertGonzalez
Can't you use the NOW() function in MySQL instead of passing the date to the DB?
Code: Select all
INSERT INTO `table` (`id`, `date`, `data`) VALUES (23, NOW(), 'Some string to enter');
Posted: Fri Aug 11, 2006 1:18 am
by matt1019
my favorite way is to do this:
make a string, lets call it todayx
now, lets echo it out:
you can refference it the same way... $todayx
hope this helps.
-Matt
Posted: Fri Aug 11, 2006 12:38 pm
by jmilane
Everah wrote:Can't you use the NOW() function in MySQL instead of passing the date to the DB?
Code: Select all
INSERT INTO `table` (`id`, `date`, `data`) VALUES (23, NOW(), 'Some string to enter');
I could, but Id rather just strip the time off of it here. I need to break it up into year/month/day and handle each piece as a seperate field.
Thanks, all.
Posted: Fri Aug 11, 2006 12:53 pm
by RobertGonzalez
Have you read through the MySQL manual on date and time functions? They have something for everything you want to do. And doing it DB side is faster for your script than processing it code side.
Posted: Fri Aug 11, 2006 12:57 pm
by jmilane
Everah wrote:Have you read through the MySQL manual on date and time functions? They have something for everything you want to do. And doing it DB side is faster for your script than processing it code side.
I have looked. This isnt straightforward. Thanks, though. I will look again. There is too much to learn... my head it going to pop.
Posted: Fri Aug 11, 2006 2:30 pm
by feyd
When NOW() is applied to a DATE field, only the date is kept. I would advise that you keep the date as a single field and allow your database to handle it as a real date.