[development] submitting date values to database using date_popup type form api

nan wich nan_wich at bellsouth.net
Fri Feb 4 15:24:31 UTC 2011


The value is returned as an associative array, with keys of "year," "month," and 
"day." Each value is a string, but they are validated to ensure they are 
numeric, etc. You will have to massage the array data into whichever format you 
want. That is a simple task, but if you use the Unix timestamp format, watch out 
for timezone issues. As for which data type to use in the database, a lot 
depends on what date ranges you anticipate using, and how you want to use them. 
Typically Drupallers use the Unix timestamp, but that hits its limit in 2038 
(much like the dreaded Y2K issues 11 years ago). BTW, the Date module does not 
guard against this.

Retrieving that data is going to be the same process in reverse. Drupal has the 
useful date_format() function, but that only works on Unix timestamps (maybe 
this will change in D8). PHP itself has several ways to deal with date formats, 
but does not provide translation as Drupal's function does.
 
Nancy
 
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.



________________________________

From: mahesh gajabar
Hi,
I have a form element called date in my module file like this ..
 $format='Y-m-d';
   $form['date'] = array(
    '#type'  => 'date_popup',
    '#title' => t(' Date'),
    '#date_format' => $format,
);

date pop up Is coming fine and I can select date easily. Issue ahead me is to 
submit this date to database and show it in my edit form with default value 
which I submitted in databse. How I can submit this date to database (which is 
the better  data type in table for this field?  Is it int or date or datetime in 
mysql?) and retvieve it in Year-Month-date format to show on screen. I am new 
baby to drupal .Please help me guys.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20110204/2b646ca3/attachment.html 


More information about the development mailing list