Community Documentation

Add Hebrew Date using a custom field

Last updated March 17, 2011. Created by Amir Simantov on November 3, 2009.
Edited by Pomliane, VM. Log in to edit this page.

Following instructions are the product of a forum discussion taken in Drupal Israel site: http://www.drupal.org.il/node/3749 and are based on Mooffie's code with help from Yuval Hagger.

1. In Computed code paste the code that you find here:
http://drupa.co.il/_files/forexternsites/drupal.org-node-622098.txt

2. In Display format paste this:

<?php
$display
= $node_field_item['value'];
?>

3. If you choose to store it in the database, varchar with 25 characters will be fine.

Note: For English names and calculation of the Jewish data look inside the code for "ELUL".

Comments

the file you link is not

the file you link is not UTF-8 encoded.

Also, this form of code posting is not very usable. if you can make a module out of it you'll get usage stats, bug reports and version control.

--yuval

I couldn't find the code referenced above, and had to figure this out again, so here it is in case anyone else finds themself in a similar situation.

This code converts a cck field called gregorian_date to a string displaying the complete hebrew date:

Computed Code (PHP)

// grab the gregorian date field from this node
$items = field_get_items($entity_type, $entity, 'field_gregorian');
$item = array_pop($items);

$gregorian_date_str = $item['value'];
$gregorian_date = strtotime($gregorian_date_str);

// convert to julian date, and then jewish date
$julian_date = GregorianToJD(format_date($gregorian_date, "custom", "n"), format_date($gregorian_date, "custom", "j"), format_date($gregorian_date, "custom", "Y"));
//$entity_field[0]['value'] = $julian_date;

$hebrew_date = jdtojewish($julian_date);

$hebrew_month_name = jdmonthname($julian_date, 4); 
list($hebrew_month, $hebrew_day, $hebrew_year) = split('/',$hebrew_date);
// list($hebrewMonth, $hebrewDay, $hebrewYear) = split('/',$hebrewDate);
 
$entity_field[0]['value'] = "$hebrew_day $hebrew_month_name, $hebrew_year";

DISPLAY CODE (php) // this is the default

$display_output = $entity_field_item['value'];

Page status

Needs updating

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Site administrators

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here