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

A place for users and developers of the Xataface to discuss and receive support.

Postby 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
rbchen
 
Posts: 21
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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

--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby rbchen » Thu Apr 05, 2007 2:13 pm

Thanks Steve! It works.

Raymond
rbchen
 
Posts: 21
Joined: Wed Dec 31, 1969 5:00 pm

Re: How to initialize a Date field to today's date?

Postby 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
mikep
 
Posts: 44
Joined: Fri Apr 24, 2009 2:21 pm

Re: How to initialize a Date field to today's date?

Postby 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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: How to initialize a Date field to today's date?

Postby 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
mikep
 
Posts: 44
Joined: Fri Apr 24, 2009 2:21 pm

Re: How to initialize a Date field to today's date?

Postby 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"?
Last edited by neotrode on Mon Dec 20, 2010 11:19 am, edited 1 time in total.
neotrode
 
Posts: 26
Joined: Mon Dec 20, 2010 11:08 am

Re: How to initialize a Date field to today's date?

Postby shannah » Mon Dec 20, 2010 11:18 am

shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: How to initialize a Date field to today's date?

Postby 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
 
Posts: 26
Joined: Mon Dec 20, 2010 11:08 am

Re: How to initialize a Date field to today's date?

Postby 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!
neotrode
 
Posts: 26
Joined: Mon Dec 20, 2010 11:08 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 26 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved