Hello everybody
I'm completly lost with my dates.
I've built a form to add holidays periods.
This is the item for first day of holidays

mymodule_holidays_add_form($form_state, $holidays_id =NULL)
if (!empty($holidays_id)) {
  $holidays_item = db_query("SELECT a.* FROM {restobook_holidays_periods} AS a WHERE id= %d", $holidays_id);
  $data = db_fetch_object($holidays_item);
  $form['id'] = array('#type' => 'hidden', '#value' => $data->id);
  drupal_set_title(t('Edit holidays: %id', array('%id' => $data->id)));
}
$form['beginning_datetime'] = array(
  '#type' => 'date',
  '#title' => t('Beginning day'),
  '#description' => t('The first day off'),
  '#default_value' => array(
    'month' => format_date(!empty($holidays_id)? $data->beginning_datetime : 1,'custom', 'n'),
    'day' => format_date(!empty($holidays_id)? $data->beginning_datetime : 1,'custom', 'j'),
    'year' => format_date(!empty($holidays_id)? $data->beginning_datetime : 1,'custom', 'Y'),
		),

This is my stored value in a sql datetime format in my table
2012-02-09 00:00:00
and in edit mode my field displays : Jan - 1 - 1970 .
As I can see in debug my $timestamp is not in the correct format, 4568567 for ex, but is 2012-02-09 00:00:00
Is there something to do to get the UNIX timestamp for format_date?
(the slope to jquery datepicker popup is pretty steep indeed ;(

Comments

artatum’s picture

Finally I switched to date popup field but now I cannot store my dates...
I've tried type = datetime for my form elements beginning_datetime, ending_datetime, then varchar in schema with %s in query but no joy,
I can get the date and time pickers but no date in my table.

db_query("INSERT INTO {restobook_holidays_periods} (beginning_datetime, ending_datetime, activated) VALUES (%s, %s, %d)", $form_state['values']['beginning_datetime'], $form_state['values']['ending_datetime'], $form_state['values']['activated']);
artatum’s picture

%s ?
VALUES ('%s', '%s', %d)"
Thx for the quotes.