I don't know if I am blatantly missing something or what, but I'm having a problem getting a correct birthdate displayed in my custom profile. I have added a Date component to the profile and, on the user profile, I'm trying to show a formatted date. This is the code that I'm using:

  $tstamp = mktime(0,0,0, $user->profile_birthdate["month"], $user->profile_birthdate["day"], $user->profile_birthdate["year"]);
  // Note: I also tried adding value 1 to the end of the parameter list, but that didn't help either
  $age = age($tstamp);
  $birthday = format_date($tstamp, 'custom', 'F j, Y') . ' (' . $age . ')';

However, whatever date I set in the profile, $birthday always formats the date a day too early. So, a birthdate of Mar 24th, will show up in $birthday as Mar 23. The timestamp is correct in the age() function. It appears to be the format_date that throws it off.

What am I missing?

Comments

zeta ζ’s picture

Where is function age() defined?
___________________
It’s in the detaιls…

budda’s picture

Sounds like a fun old timezone/daylight savings time issue. Rather than setting the time to 00:00:00 add on a few hours to prevent the time going -X hours in to the previous day. I usually stick the time to be half way through the day.

--
Ixis (UK) providing Drupal consultancy and Drupal theme design. Check the portfolio.

jdevries’s picture

That did the trick. Never realized it would be that simple. Thanks!

@zeta-zoo: I stuck the age function just above that piece of code. The function is mainly there, because I offer my users the option in their profile how they want to show their birthdate and/or age (if they want to in the first place). I use the $age variable in two places.

zeta ζ’s picture

Where it is defined is of little consequence. I was thinking more about whether it was php-, drupal- or user-defined. I was a bit confused, and thought it was the age that was wrong, and could be corrected by making the time not affect the date, as budda’s suggestion has done.

Please ignore me :-|
___________________
It’s in the detaιls…