Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a method on my code that stores the birthday of users on a Sharepoint profile property (BirthDay).

This property only accepts the format "yyyyMMddHHmmss.0Z" so i have the following code:

_profile[PropertyConstants.Birthday].Value = birthday.ToString("yyyyMMddHHmmss.0Z", CultureInfo.InvariantCulture);

The problem is, when it converts the date, it always gives me a day less than the actual dateTime i'm using.

Let's say i have the following:

DateTime bDay = new DateTime(1972, 10, 02);
DBField = bDay.ToString("yyyyMMddHHmmss.0Z", CultureInfo.InvariantCulture);

When i check on the profile of the user, the date in there is 10/01/1972 instead of 10/02/1972.

I'm in Brazil so i don't know if it's a CultureInfo thing (already tried our CultureInfo("pt-BR") and still gives me a day less) or what.

Any ideas how can i make it not take that 1 day off?

Thanks in advance.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

It's because you're setting the time in Zulu, but you're not actually located in UTC-00. Dates in SharePoint get stored with the time portion, which gives a nice complication for recording date events where the time is not relevant.

Add twelve hours to your date before storing it and then it should appear correct for everyone.

If you have any logic that's dependent on this date, make sure to strip the time before doing a comparison so that you get the right continuous date range.

share|improve this answer
    
Thanks Drew, the UTC-00 is that 0Z on the format i'm using, if so, how i can i find out which one the correct 'Z' for Brazil? –  C. Hoffmann Nov 1 '12 at 13:39
    
No need to change the Zulu specifier - just add 12 hours to your time. So, rather than using DateTime bDay = new DateTime(1972, 10, 02); try DateTime bDay = new DateTime(1972, 10, 02, 12, 0, 0);. I find this is a better way to record timestamps for all-day events that don't involve start-stop times, that way the date itself is accurate anywhere in the world. Since Brazil has multiple timezones, you wouldn't want to make the timezone set to one particular region. Should you prefer to adjust the timezone instead, I believe you'd change 0Z to -5Z, adjust for your UTC preference. –  Drew Lanclos Nov 1 '12 at 13:48
    
Thanks a Lot Drew. I did what you suggested (add 12 hours) and it worked just right. Saved my day. –  C. Hoffmann Nov 1 '12 at 13:51
add comment

Use DateTime.ToUniversalTime to convert you date to UTC, then use SPUtility.CreateISO8601DateTimeFromSystemDateTime to create the ISO86201 string like this:

_profile[PropertyConstants.Birthday].Value = SPUtility.CreateISO8601DateTimeFromSystemDateTime(birthday.ToUniversalTime());
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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