Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting date into my Database 1

Status
Not open for further replies.

Sitehelp

Technical User
Joined
Feb 4, 2004
Messages
142
Location
GB
Any ideas how I insert a PHP date function as:

<?php $today = date('d-m-Y');
print &quot;$today&quot; ?>

into a database. It is in a form that submits a number of boxes together into one record within the DB. The date displays fine on the first page using the above code, when you click submit, however, it says that the text box cannot be null. I have the date appearing in the text box using the following code:

value=&quot;<?php print &quot;$today&quot; ?>&quot;

Any ideas why it wont recognise any text when submitting it???????????? All the names are correct within the code, I have double checked i.e. it is looking at the correct text box. Cheers for this, this is important to running my site correctly!
 
You could use a hidden field. thats what i use for my dates from a form!
Code:
<input type=&quot;hidden&quot; name=&quot;thedate&quot; value=&quot;<?php echo(date(&quot;d/m/Y&quot;)); ?>&quot;>
or you could put the code in where you insert the data into the table.
Code:
$date = date(&quot;d/m/Y&quot;));

gd luck!

Martin

Computing help and info:

 
Mysql default dates are in YYYY-MM-DD format, you will need to make your date compatible with that first ? or have you just used a text/varchar field for this date in the database?

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Same answer as to your other post:
MySQL keeps dates and times. You can use the SQL function NOW() to set a date/time column to the current date.
 
yeah...the date needs to be in the same format as the date in the DB. so, i would look at the way the DB holds the date value and change the code that way.

hope this helps


David Kuhn
------------------
 
Yeah I thought that so I submitted the date as a text field as I wanted dd/mm/YYYY. This being the case it just doesnt want to recognise anything in the text box even though it has been added using that PHP script previously mentioned! I would like the date to be generated automatically (dd/mm/YYYY) as the user shouldnt be able to generate the date themselves in the circumstance I need it for. Any ideas? ta!
 
let me explain that. use &quot;d/m/Y&quot; to get dd/mm/yyyy. if you want to get dd-mm-yyyy use &quot;d-m-Y&quot;. you can also interchange the date...say you want to have mm/dd/yyyy, then you would use &quot;m/d/Y&quot;.

hope that this helps, it should fix your problem

David Kuhn
------------------
 
That works great!!!! cheers for that!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top