Showing posts with label DateTime. Show all posts
Showing posts with label DateTime. Show all posts

Friday 9 December 2011

Add Expiry Date to a List

Problem:  I have a list and each time the list item is approved, I need to add 180 days to the expiry date.

Initial Hypothesis: Create a Date and Time site column in the list.  Edit the "Calculated Value" box with a formula that will add 180 days to the current date.

Resolution: The formula to move the expiry date 180 days from the current date is:
=DATE(YEAR(Today),MONTH(Today),DAY(Today)+180)

Tuesday 16 November 2010

DateTime control default behaviour

Problem: The SharePoint date time control's default behaviour is to returns the current date and time when no date has been selected.
Initial Hypothesis: Validate the control to pre insert to check if it is selected, if no date time is choosen don't update the record.
Resolution:  The Property IsDateEmpty returns "false" if the date has been input.
Code:
if (!dtMyBirthday.IsDateEmpty)  { // ... User has delected their birthday date so insert into SQL table or list }
Read More:
http://karinebosch.wordpress.com/sharepoint-controls/datetimecontrol-control/

Monday 1 November 2010

SharePoint DateTime format is incorrect

Problem: The SharePoint DateTimeControl displays the date in US format i.e. 1033 or mm/dd/yyyy despite me changing the site collections regional settings.
Site Settings > Regional Settings > Locale > Select [English (United Kingdom)]

Inital Hypothesis: In MOSS changing the Locale did not change the format of the DateTimeControl. 
Resolution: This is still the case, you need to explicitly set the local on eash DateTimeControl.  You can set it to be the same as the site's local.
E.g. myDateTimeControl.LocaleId = SPContext.Current.Web.Locale.LCID 
Or set the "LocaleId"attribute of the SharePoint DateTime control
E.g. SharePoint:DateTimeControl runat="server" LocaleId="2057"

=========================
Tip: Changing the Regional settings will affect the curreny columns.

List of Locale's: http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx

====================

Using CAML and SPQuery to query using dates

Problem: Using SPQuery I can't filter using a datatime parameter.
Hypothesis: I can see my custom web part code is formatting the DateTime selection (SharePoint:DateTimeControl) differently in my custom code CAML than the CAML generated by U2U.
Resolution:
Use the Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime() method to get your DateTime control value into the correct format.
SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.UtcNow)

More Info:
http://blogs.msdn.com/b/saurabhkv/archive/2008/05/05/spquery-with-boolean-and-datetime.aspx
http://snahta.blogspot.com/2009/07/spquery-few-important-things.html
http://www.aidangarnish.net/post/Using-SPQuery-and-CAML-to-filter-and-order.aspx