Hi,

I'm using date_picker in my module. I have the following code:

  $form['start'] = array(
    '#title' => t('Arrive'),
    '#type' => 'date_popup',
    '#default_value' => 'YYYY-MM-DD',
    '#date_year_range' => '0:+3',
    '#size' => 12,
    '#required' => true,
  );

But the time field is displayed, though the field is not required and not specified in #default_value.

Is there a way that the time field component can be removed when using '#type' => 'date_popup' in a custom module?

Many thanks for any light you can shed on this matter.

Comments

karens’s picture

Status: Active » Fixed

You don't have this set up right. You need a complete date, like YYYY-MM-DD HH:MM:SS for the default date (you can use zeros for non-needed hours, minutes, and seconds), and you also need #date_format, which is where you identify that you only want a year, month, and day, like 'Y-m-d'.

baronmunchowsen’s picture

Hi KarenS

Thankyou for your help. This worked like a charm:

  $form['start'] = array(
    '#title' => t('Arrive'),
    '#type' => 'date_popup',
    '#date_format' => 'm/d/Y',
    '#default_value' => 'YYYY-MM-DD 00:00:00',
    '#date_year_range' => '0:+3',
    '#size' => 12,
    '#required' => true,
  );

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

abdelatifs’s picture

$form['rental_date']['pick_up'] = array(
'#type' => 'date_popup',
'#title' => 'Pick Up Date',
'#date_format' => 'm/d/Y',
'#default_value' => 'YYYY-MM-DD 00:00:00',
'#size' => 10,
'#maxlength' => 15,
'#required' => TRUE,
);

I've tried this and the field is populated correctly. But when I submit my form and try to display the result i get this: "2011-01-14 00:00:00" when i'd like to get this "01/14/2011"
Any reason why?
Thank you guys

Mohamed Hafez’s picture

Issue summary: View changes

thank u the below code is working with me as charm

<?php
    $form['from'] = array(
                    '#title'  => t(' تاريخ البداية'),
                    '#type'   => 'date_popup',
                    '#date_format'   => 'Y-m-d',
    );
?>