dd/MM/yyyy

CAML Query Search Between Two Date Ranges : SharePoint

SPSite site = new SPSite(“http://localhost:3001”); SPWeb web = site.OpenWeb(“MyWeb”); SPList list = web.Lists[“MyList”]; //RequestStartDate & RequestEndDate will be passed in mm/DD/yyyy format. //They can extend  to work with time also. string startDate = (SPUtility.CreateISO8601DateTimeFromSystemDateTime(Convert.ToDateTime(this.RequestStartDate))); string endDate = (SPUtility.CreateISO8601DateTimeFromSystemDateTime(Convert.ToDateTime(this.RequestEndDate))); SPQuery query=new SPQuery(); query.Query = “<Where><And><Geq><FieldRef Name=’Date_x0020_of_x0020_Meeting’ /><Value Type=’DateTime’>” + startDate + “</Value></Geq><Leq><FieldRef Name=’Date_x0020_of_x0020_Meeting’ /><Value Type=’DateTime’>” + CAML Query Search Between Two Date Ranges : SharePoint

Object cannot be cast from DBNull to other types

Sometimes you need to code around dates in your program. Today i will discuss about the common error we get while displaying a date from back end to front end. What if you have blank/null value inserted in your back end for date and when you get this date to front end and try to Object cannot be cast from DBNull to other types

Validate Date in dd/MM/yyyy format

Sometime we need to validate our control for proper date format in dd/MM/yyyy format. Below is the code snippet for that. Main part of code snippet is the Regular expression i used to validate. <asp:TextBox ID=”txtDate” runat=”server”></asp:TextBox> <asp:RegularExpressionValidator ID=”revDTTest” runat=”server” ControlToValidate=”txtDate” ForeColor=”Red” ErrorMessage=”Enter Valid Date in dd/mm/yyyy format.” SetFocusOnError=”True” Display=”Dynamic” ValidationExpression=”(^((((0[1-9])|([1-2][0-9])|(3[0-1]))|([1-9]))\x2F(((0[1-9])|(1[0-2]))|([1-9]))\x2F(([0-9]{2})|(((19)|([2]([0]{1})))([0-9]{2}))))$)“></asp:RegularExpressionValidator>

Convert date from dd/MM/yyyy to MM/dd/yyyy for storing in SharePoint list or Sql Server Database

I was working on a custom web part that takes the date in Indian format e.g. dd/MM/yyyy while inserting the record in SharePoint custom list. But as we know that SharePoint custom list insert the date value as MM/dd/yyyy format. So it was throwing me the error for invalid string format so below is the Convert date from dd/MM/yyyy to MM/dd/yyyy for storing in SharePoint list or Sql Server Database