Skip to main content

Date

Drupal Date Manipulation

Submitted by amitsedai on
An easier way of getting difference between dates is achieved using the DateObject provided by Drupal. <?php $now_date = date_now(); $last_donation_date = new DateObject($node->field_date[LANGUAGE_NONE][0]['value'], 'UTC'); // Get difference in days in positive if $now_date is greater than $last_donation_date $diff_days = $last_donation_date->difference($now_date, 'days', FALSE); ?> Print a Date Object in any format using date_format_date: <?php print date_format_date($date_object, 'custom', 'Y m d'); ?> -- Source http://drupalcontrib.org/api/drupal/contr

Dates using PHP

Submitted by amitsedai on
Time and again date parsing issue comes up and I find myself looking all over the net for finding ways to do the same. This post is created to compile all such ways as I encounter: Parsing Dates If your date format is: yyyy-mm-dd, you can simply use strtotime and date function to get the desired date format $data[] = date( 'd-m-Y', strtotime('2012-03-21')); //get the format as 21-03-2012
Get Dates Using Strotime strtotime can recognize certain keywords. <?php echo strtotime('now'); echo strtotime('+4 days');