[development] problem with custom date and timezones

Lluís enboig at gmail.com
Fri Jul 17 12:53:40 UTC 2009


I have set timezone to UTC in admin/settings/date-time and no timezone for user.

So my problems are:
a) How do I have to store the date? is mktime(0,0,0,$month,$day,$year); correct?
b) If I want to use the date in views, how should I store it in
database? I use int(11) now
c) How can retrieve $month, $day, $year to make the form again?


On Fri, Jul 17, 2009 at 2:11 PM, Seth Freach<sfreach at gmail.com> wrote:
> Lluís,
>
> time() will return a value relative to the epoch, which is epicentered in
> GMT.
> date() takes that value and returns a local time based on it.  IE, date()
> knows about the computer's timezone and takes it into account.
>
> Drupal's format_date() function uses gmdate() internally, which, unlike
> date(), does not do local timezone offsetting. gmdate() returns the formated
> date string in GMT.  The reason format_date() does this is because it wants
> to return a time that has meaning to the individual user's location, which
> is not necessarily the computer's location, nor are all users always in the
> same timezone.  Drupal does the timezone offsetting itself to allow a system
> default timezone and individual user configurable timezones too.
>
> Double check your Drupal timezone settings at q=admin/settings/date-time and
> possibly your user timezone settings at q=user/$uid/edit
>
> Seth
>
> Lluís wrote:
>
> Making some research my problem is with format date:
>
> $node->data_assentament -> 1247781600
> date("d-m-Y H:i", $node->data_assentament) -> 17-07-2009 00:00
> format_date($node->data_assentament,'medium') -> Dij, 07/16/2009 - 22:00
>
> (I need the date in dd/mm/YYYY format)
>
> Should I avoid format_date() or there is a better way to solve this?
>
> On Thu, Jul 16, 2009 at 5:40 PM, Lluís<enboig at gmail.com> wrote:
>
>
> I have created a custom node type. I have a date field which I created
> as int in order to use it in views, being able to sort it, format,
> etc....
>
> My problem right now is that when inserting a node with one date, it
> appears as "day before" when viewing the node. How should I save it to
> avoid this problem?
>
> My form looks like
>  $arrayF=getdate(($node->data_paper>0 ? $node->data_paper : time()));
>  $arrayF['month']=$arrayF['mon'];
>  $arrayF['day']=$arrayF['mday'];
>  $form['data_paper_array'] = array(
>    '#type' => 'date',
>    '#title' => 'Data Factura',
>    '#default_value' => $arrayF,
>    '#required' => TRUE,
>    '#weight' => -9,
>  );
>
> My insert query looks like
>  $dateF=$node->data_paper_array;
>  $factura_tmsp=mktime(0,0,0,$dateF['month'],$dateF['day'],$dateF['year']);//
>  $date['year']."-".$date['month']."-".$date['day'];
>  $node->data_paper=$factura_tmsp;
>  db_query("INSERT ......);
>
> And my theme function:
>  $output.="<li><b>Data Factura:</b>
> ".format_date($node->data_paper,'small')."</li>";
>
>
> Any hint/advice? Thanks
>
> --
> *La vida és com una taronja, què esperes a exprimir-la?
> *Si creus que l'educació és cara, prova la ignorància.
> *La vida és com una moneda, la pots gastar en el que vulguis però
> només una vegada.
> *Abans d'imprimir aquest missatge, pensa en el medi ambient.
>
>
>
>



-- 
*La vida és com una taronja, què esperes a exprimir-la?
*Si creus que l'educació és cara, prova la ignorància.
*La vida és com una moneda, la pots gastar en el que vulguis però
només una vegada.
*Abans d'imprimir aquest missatge, pensa en el medi ambient.


More information about the development mailing list