How to initialize a Date field to today’s date?

Archived from the Xataface Users forum.

rbchen — Wed Apr 04, 2007 3:45 am

I have a DB column defined as Date. Quick Forms renders it as a text field with the Calender picker. Since I am not allow to use mySQl function to set the default date for the column, how do I set it to today’s date in the “New Record” page?

Many thanks in advance for any insight!!

Raymond


shannah — Thu Apr 05, 2007 10:48 am

Hi Raymond,

There are a couple of choices here.Ê If all you want is to have the column act sort of like a timestamp, you can use the timestamp parameter in the fields.ini file:

http://framework.weblite.ca/documentation/manual/fields_ini/field_timestamp

Alternatively you can set the default value using the %fieldname%__default() method in the delegate class:

e.g.

function mydatecol__default(){
ÊÊÊ return date(‘Y-m-d’);
}

Hope this helps a little.

-Steve


rbchen — Thu Apr 05, 2007 2:13 pm

Thanks Steve! It works.

Raymond


mikep — Wed Aug 11, 2010 1:47 pm

I added the function to the table’s delegate class:

function mydatecol__default(){
return date(‘Y-m-d’);
}

but the field is populated with 0000-00-00. Did I do something incorrectly?

Mike


shannah — Wed Aug 11, 2010 2:05 pm

That snippet assumes that your date field is named mydatecol. You should substitute the field name for ‘mydatecol’.
-Steve


mikep — Sat Aug 14, 2010 10:08 am

I substituted the actual name of the column for mydatecol. When I do that, the default is 0000-00-00. Without this function, there is no default.

Mike


neotrode — Mon Dec 20, 2010 11:10 am

Unfortunately, Shannah’s link doesn’t exist anymore. Can someone please point me to the replacement link?

Also, I looked into Deligating a program.php as per the docs. However, how can I make that specific to the particular website? It appears that Xataface simply creates a two file installation containing a config.ini and an index.php file. Then it refers to the main installation of Xataface. If I make a website under folder “test-site” and have the two created files point to the Xataface directory, how do I isolate the program.php file to only perform for the “test-site”?


shannah — Mon Dec 20, 2010 11:18 am

http://xataface.com/wiki/timestamp


neotrode — Mon Dec 20, 2010 11:21 am

Nice! Sounds easy enough and specific to the website installation in question. I will give a it a shot. Thank you for the exceptionally speedy reply.


neotrode — Mon Dec 20, 2010 11:30 am

Perfect! Thanks. I also understand how to isolate the configuration. I overlooked the example stating to create subfolders like “tables” in the website in question. That did it!