I am using custom module in drupal and i am working in hook_form_alter() .
I am passing date format as this type.
But it is not working and filed type is DATETIME.
Please help me...
$form['field_res_inq_time_arrival'][0]['#default_value']['value'] = date('d/m/Y - h:m',strtotime('2011/04/13'));
Regards
Aasim Afridi
From Form Api Reference:
The #default_value will be today's date if no value is supplied. The format for the #default_value and the #return_value is an array with three elements with the keys: 'year', month', and 'day'. For example, array('year' => 2007, 'month' => 2, 'day' => 15)
Related
I am trying to make a date input that defaults to the value that is already in the database.
However, when I set the month, year, and date to the database values, the month, date, and year attributes are set on the select element but the page still displays the current date as the default values. When the form is submitted, today's date is stored in the database.
Heres the code:
$mail_date_time = \explode(" ",$campaign["MailedDate"]);
$mail_date = explode("-",$mail_date_time[0]);
echo $this->Form->create("Campaign");
echo $this->Form->input("MailedDate",array(
'month' =>strtotime($mail_date[1]),
'year' => strtotime($mail_date[0]),
'day' => strtotime($mail_date[2])
));
echo $this->Form->end("Submit");
$mailed_date turns out to be: [0]=2009 [1]=11 [2]=11
Does anyone know how to solve this?
Thanks!
The Cake form helper includes formatting of dates... i.e. 'dateFormat' => 'DMY' in your MailedDate input.
The value displayed by the input field would default to the value contained in $this->data and can be overwritten completely using 'default' => 'value', or prefilled using 'empty' => 'value'.
In order to precompile the datetime fields is necessary to use the 'default' keyword:
$mydate = '2015-09-10 06:40:00'
echo $this->Form->input('datetime', array(
'label' => 'Date 2',
'default' => $mydate
));
I am trying to make an area on my Wordpress site that checks the date field on each of my custom post type posts each time I get on for any dates that are 7 days or less until the current date and then displays the corresponding post title. If you have questions about any of that, please just ask, it is hard to really explain it.
I would like to put an if statement in there that just says if any of the dates are 7 days or closer to the current date, display the title of that post.
Problems:
The whole the_field( 'contract_sign_date' ); function displays the date as mm/dd/yy, so I'm not sure if subtracting the_field( 'contract_sign_date' ) by the current date will even come out right.
If problem 1 would for some reason work, what if the contract sign date is the first of the month? 1 - 7 will = -6 instead of the current date.
Like I said, if you have questions about any of that, please just ask, it is hard to really explain it.
Here you go this may help you get what you may need from wordpress
$contract_date = date(the_field( 'contract_sign_date' ));
$contract_date = strtotime ('-7 days', strtotime($contract_date) ) ;
$args = array(
'date_query' => array(
array(
'after' => array(
'year' => date ('Y', $contract_date),
'month' => date('m', $contract_date),
'day' => date('d', $contract_date)
),
),
),
);
$query = new WP_Query( $args );
I'm trying to select the values that fall between 2 dates, so I'll have to use <= and >=, however, my query is seemingly behaving as just less than or greater than and not considering values equal to the date.
I'm using CakePHP which saves dates in "Y-m-d h:i:a" format. I wanted to find dates on given week intervals (starting on Sundays), so I used the following.
$start_date = date('Y/m/d', strtotime('last Sunday', strtotime($timestamp)));
$formatted_start_date = str_replace("/","-",$start_date);
I tried to do find $start_date formatted as "Y-m-d" but then it wouldn't find the correct date, so I switched it to the way it is and used str_replace to format it to using "-" instead of "/".
$date_query = $this->Order->query("select * from orders where id = '$id' and created => '$formatted_start_date' and created <= '$current_timestamp' ");
Considering the time values in my database are in "Y-m-d h:i:a" format, can I use "Y-m-d" for date comparison? Is it possible to do a MySQL query that involves both LIKE and <= ?
No need to do a str_replace() - just get the Y-m-d:
$start_date = date('Y-m-d', strtotime('last Sunday', strtotime($timestamp)));
Then, instead of manually creating a query, use the CakePHP conventions (yes, you can use Y-m-d for date comparison even though the datetimes stored in the database are Y-m-d H:i:s)
$this->Order->find('all', array(
'conditions' => array(
'id' => $id,
'created >=' => $start_date,
'created <=' => $end_date . ' 23:59:59',
'my_field LIKE' => '%whatever%'
));
Though - this seems kind of strange - usually you're either looking for something by 'id' OR by a date range - not both. But - maybe you have a reason :)
And as you can see above, yes, you can add a 'LIKE' also if you need.
Above answer is totally correct, but you can take easier approach using cakePHP time helper, which has function daysAsSql, it transcribes and time-readable strings into database range.
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::daysAsSql
Just add condition's array like this.
$resl = $this->DBNAME->find('all',array(conditions=>array('date1>date','date1<date')));
Replace 'date' with your date.
This is worked for me.
Try this in your controller
$searchTutorQuery = $this->Tutordetails->find('all', array(
'conditions' => array(
"User.zip" => $zipcode1,
"Tutordetails.user_id"=>$uid,
"Tutordetails.subject_id" => $subjectName,
"Tutordetails.hourly_rate >=" => $hourly_rate
),
//"User.id =" => $userid,
'fields' => array('user_id', 'Tutordetails.subject_id', 'Tutordetails.hourly_rate',
'User.zip', 'Tutordetails.zip'),
'order' => array('Tutordetails.id DESC')
));
I have to display date alone in sfWidgetFormDate but I want date and month to be passed in hidden.
I have given as:
$this->widgetSchema['fellowship_admission_date'] = new sfWidgetFormFilterDate(array(
'from_date' => new sfWidgetFormDate(array('format' => '%year%')),
'to_date' => new sfWidgetFormDate(array('format' => '%year%')),
'with_empty' => false
))
It displaying only year but I want to pass month and day in 'from_date' and 'to_date' default as '1' as hidden.
Why don't you display the entire date, and hide day and month with jQuery?!
It could be a good and fast solutions...
I have an array like so which has the column names of the table on the left and the associating values on the right.
$proceduredata = array
(
'patient_id' => $patientfk,
'name_id' => $procedurenamefk,
'department_id' => $departmentfk,
'dosage_id' => $dosagefk,
'edocument' => NULL, //not implemented yet
'user_id' => $this->session->userdata('userID'),
'duration' => NULL, //not implemented yet
'submitted' => date('d-m-Y H:i:s', now()),
'comment' => NULL, //to be implemented
);
This array is then passed into a SQL insert function. The insert works fine but my "Submitted" column is getting values of this only:
0000-00-00 00:00:00
I made sure the time formats are matching? Is there something I have missed thanks.
change the date format
submitted' => date('Y-m-d H:i:s', now())
I believe that the "now()" function is a sql function and you are using PHP with the "date()" funciton. Try changing "now()" to "time()" which will give you a proper unix timestamp that the "date()" function can use to create a properly formatted date.
EDIT: I just realized I am not familiar with codeignighter, so please excuse me if the "now()" function is part of that framework.
now() is not a function, change now() to time(). Alternatively, date()'s second paramater is optional if you omit it date automatically uses the current date/time:
echo date('d-m-Y H:i:s');
will echo the current date/time in the format requested.