Closed (fixed)
Project:
Date
Version:
7.x-2.x-dev
Component:
Date API
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
28 Mar 2011 at 16:26 UTC
Updated:
4 Mar 2013 at 18:33 UTC
Jump to comment: Most recent
Comments
Comment #1
Anonymous (not verified) commentedsubscribe
Comment #2
gagarine commentedrender() doesnt work neither...
Comment #3
valderama commentedgood question :)
i tried
format_date(strtotime($field_news_date['de'][0]['value']), 'medium', '', 'Europe/Paris');but the timezone seems not to be applied (all dates are two hours early)
Comment #4
gagarine commentedmore about the API...
Comment #5
adaddinsaneI have a field for date-of-birth (field_dob) which has Y-m-d granularity, so no timezone conversion. But when it's stored it's subtracting an hour - because I'm in the UK on British Summer Time, presumably.
So a field_dob might look like this:
value (String, 19 characters ) 1958-09-21T23:00:00
timezone (String, 13 characters ) Europe/London
timezone_db (String, 3 characters ) UTC
date_type (String, 4 characters ) date
Where the date of birth was 22nd Sept 1958. I then put the date into a DateObject:
$dobj = new DateObject($item['value'], $item['timezone']);
Which doesn't give me the right answer. So.....
Working from the basic principle that the date module knows how to get it right :-) I did some investigating and I can see what we need is the code in the helper function date_formatter_process() in the date.module
It's going to be ugly.
Ah well.
Comment #6
cappadona commentedsubscribe
Comment #7
joelcollinsdc commentedsubscribe
Comment #8
joelcollinsdc commentedCan someone tell me if this is right? Maybe i'm dense but this has been really frustrating...
I'm just trying to get the date out of the field in a preprocess function. (in the correct timezone)
$db_value = $node->field_event_date[$node->language][0]['value'];
$date = new DateObject($db_value,'UTC',DATE_FORMAT_ISO);
$variables['event_date'] = format_date($date->format('U'),'custom','F j, Y g:i a');
Comment #9
gagarine commentedI'm still having this problem... nobody can help about it?.
EDIT if you have the object it's easy you can just do:
But in the tpl we don't have the object :(.
Comment #10
karens commentedThe formatter has all the values you want. You can create a custom theme to override the current themes (date_display_single and date_display_range) and you will have all the values and you can do anything you like with them.
Comment #12
michiellucas commenteddid anyone find a solution,
is there a D7 date_convert function?
Comment #13
adaddinsaneI do have a solution but it's tied up in a module which I hope to release some time soon - it allows you to fetch field data in a variety of ways and sorts out all these niggling little details. (Sorry I can't do it straight away - real life has me stupidly busy making websites and earning the pennies.)
Comment #14
kork commentedHere is my example code to output a custom formated date field:
you can also use the Date object from the date_formatter_process function.
Comment #15
adaddinsaneOr you could use my module field_extract which allows you to specify formatters as well as just extracting values correctly.
Just sayin'.
Comment #16
gagarine commentedThis can help http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way
Comment #17
krell commentedUsing an existing date format preset (short):
Comment #18
fureigh commentedThanks, krell!
(Tried to delete this so I could post a reply instead, but couldn't — pardon.)