submitting date values to database using date_popup type form api
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. Mahi,
If I could, I would try to use a date CCK field, and have all this taken care of for me. Just wanted to make sure that wasn't an option for you. That way you maintain no code and write nothing for the database. -Randy On Thu, Feb 3, 2011 at 11:03 PM, mahesh gajabar <mahesh143an@gmail.com>wrote:
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.
Mahi,
-- Randy Fay Drupal Module and Site Development randy@randyfay.com +1 970.462.7450
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.
participants (3)
-
mahesh gajabar -
nan wich -
Randy Fay