help getting today's date into form
Moderator: General Moderators
help getting today's date into form
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
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
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: help getting today's date into form
Code: Select all
<input value="0" type="hidden" id="qf_5d8d6e" name="custom_17" value="<?php echo date('Y-m-d'); ?>" />(#10850)
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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');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
make a string, lets call it todayx
Code: Select all
$todayx = date("F j, Y @ g:i a");Code: Select all
echo $todayx;hope this helps.
-Matt
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.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');
Thanks, all.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I have looked. This isnt straightforward. Thanks, though. I will look again. There is too much to learn... my head it going to pop.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.