PDA

View Full Version : PHP Date


Richard Diedrick
09-08-2010, 07:00 PM
I have a form that I need to have a text field that on opening the form or changing from one record to another the field shows the current date in a 2010-10-30 format. Please advise thanks.

Corrosive
09-09-2010, 06:36 AM
Hi Richard

This PHP can fetch a date for you and you can echo it out in any number of formats; http://php.net/manual/en/function.date.php

Richard Diedrick
09-10-2010, 03:32 PM
I have used the php manual in the past and if I understand it at all the date function format is date("Y-m-d") ?? What I do not get is how you call that in code. I have a text box in a form that I want to dispaly the current date in the 2010-12-31 format. Code below

<input name="firstcall" type="text" id="firstcall" value="<?php echo $row_propspects[first_call_date']; ?>" size="12" />

This shows the data in the current recordset what I want is to show the current date and then update the recordset to reflect that date. What do I replace value="<?php echo $row_propspects[first_call_date']; ?>" with? Thanks much.

Corrosive
09-10-2010, 03:46 PM
Well, without giving it too much thought you could get the current date into a variable;

<?php
$update = getdate();
?>

Then echo the result out into a hidden input in the form;

<input name="update" type="hidden" value="<?php echo("$update[mday] $update[mon] $update[year]");?>">

To be uploaded to your database.

Do check my coding and formatting though. This was done 'on the hop'. There may also be far more efficient ways to do it.

Richard Diedrick
09-10-2010, 04:26 PM
That was very much appreciated works fine. I figured that for someone who actually knew what they were doing this was pretty simple. Thanks again!:-D

Corrosive
09-10-2010, 04:56 PM
No problem. have moved thread to PHP forum btw :) Just for neatness sake.