0

I am having an interesting problem with some birthdate data in my profile nodes. I am using Drupal 6.

There are two people: Ann has the following UNIX timestamp value stored in the db: 353026800 Her profile page renders it as '1981. March 10'. When I edit the node I see also this value.

Bete has the timestamp in the db: 484696800 His profile page renders it as '1985. May 11' but when I open the node for edit then I see 1985. May 12.' in the date edit box.

The profiles are rendered in a custom tpl.php and the according piece is as follows:

format_date($p->field_szuldat[0]['value'], 'custom', 'Y. F. d.');

When I dpm the loaded node then I see that both fields have the same Europe/Budapest timezone. I see that Bete's birthdate is (not counting the days) is 1 hour before Ann's. But I see that Drupal somehow handles it and renders the values in the edit boxes properly. It might be related to DST because Bete was born in DST and Ann wasn't.

My question is: how could I make my template's date rendering also handle it properly?

I have read all the related comments to the topic, but they do not match my case because here an extra hour is being added to one of my dates.

UPDATE:

The field I am talking about is a "Datestamp" with the following configuration: "No timezone correction" is set, the granularity is only year-month-date.

  • today the issue raised again. can someone help..? – jabal Nov 1 '13 at 21:39
  • looks like the problem only exists in the DST period of the year – jabal Nov 1 '13 at 21:50
1

Solution:

$birthdate_object = date_make_date(
   $p->field_szuldat[0]['value'], 
   $p->field_szuldat[0]['timezone'],
   $p->field_szuldat[0]['date_type'],
   $granularity = array('year', 'month', 'day'));

$birthdate_formatted = date_format_date($birthdate_object, 'custom', 'Y. F j.');

This yields incorrect value in the DST period of the year (1 day difference), so very dangerous:

$wrong_birthdate = format_date($p->field_szuldat[0]['value'], 'custom', 'Y. F. d.');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.