locked
SharePoint DateTime control returning current date when no date is selected

    Question

  • Hi,
     
    In WSS 3.0, I am using sharePoint DateTime control. I retrieve the date selected by the user using SelectedDate property of the sharePoint DateTime control.

    The issue is that even when the user has not selected any date in the sharePoint DateTime control, the SelectedDate property of the sharePoint DateTime control returns current date. I guess it should return DateTime.MinValue or null when the user has not selected any date in the sharePoint DateTime control.

    Kindly clarify.

    Thanks,
    Bala
    Thursday, November 13, 2008 7:25 AM

Answers

  •  Guys,

    Even I have observed this same issue.

    I would suggest something like this -

    When you create the datetime control....set the textbox value with the default value (as u want, could be any date value )

    If i am using a SharePoint DateTime control in web part -

    CreateChildControls()

    {

    ...

    DateTimeControl dt = new DateTimeControl();

    ((TextBox)(dt.Controls[0])).Text = dt.MinValue.ToString();   //or whatever date value you would want to use

    //Now, even if the user doesnt set any value or does something, it is ensured that the default value is returned by the //dt.SelectedDate property

    }


    ________________________________________ Gautham S Pai [MCAD]
    Saturday, December 06, 2008 9:52 AM

All replies

  • Hi Bala,

      I also face same as your problem, with one more,


    I used
    <SharePoint:DateTimeControl ID="Cal1" runat="server"  DateOnly="true" LocaleId="2057" > 
               </SharePoint:DateTimeControl>

    When I inserted the value in CAML as

    +"<Field Type='DateTime' Name='ApplicationDate' >" + Cal1.SelectedDate.ToString("MM/dd/yyyy") + "T00:00:00Z</Field>" +

    Then by default it strore Current date rather my selected date.

    If you have any suggestion then plz reply me also.

    Thanks,

    Best regards,
    NiTiN.
    • Edited by Nitinb4u Thursday, November 13, 2008 8:07 AM
    Thursday, November 13, 2008 8:06 AM
  • Did you find an answer for this?   I'm having the same issue.

    Thanks,
    Brad
    Friday, December 05, 2008 7:35 PM
  •  Guys,

    Even I have observed this same issue.

    I would suggest something like this -

    When you create the datetime control....set the textbox value with the default value (as u want, could be any date value )

    If i am using a SharePoint DateTime control in web part -

    CreateChildControls()

    {

    ...

    DateTimeControl dt = new DateTimeControl();

    ((TextBox)(dt.Controls[0])).Text = dt.MinValue.ToString();   //or whatever date value you would want to use

    //Now, even if the user doesnt set any value or does something, it is ensured that the default value is returned by the //dt.SelectedDate property

    }


    ________________________________________ Gautham S Pai [MCAD]
    Saturday, December 06, 2008 9:52 AM
  • Hi,
    I also use DateTimeControl inside a webpart.  It displays ok, but whenever i click on the calendar image, the page generate the below error.  I followed the example from the site http://www.sharepoint-tips.com/2007/10/using-sharepoint-date-control-in-web.html ; it shouldn't be too hard....

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

    Server Error in '/_layouts' Application.
    --------------------------------------------------------------------------------

    Parser Error
    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

    Parser Error Message: Could not load file or assembly 'Microsoft.SharePoint.ApplicationPages' or one of its dependencies. The system cannot find the file specified.

    Source Error:


    Line 1:  <%@ Assembly Name="Microsoft.SharePoint.ApplicationPages" %> <%@ Page Language="C#" Inherits="Microsoft.SharePoint.ApplicationPages.DatePickerFrame"      %> <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <% SPSite spServer = SPControl.GetContextSite(Context); SPWeb spWeb = SPControl.GetContextWeb(Context); %>
    Line 2:  <html dir="<SharePoint:EncodedLiteral runat='server' text='<%$Resources:wss,multipages_direction_dir_value%>' EncodeMethod='HtmlEncode'/>">
    Line 3:   <HEAD>
     

    Source File: /_layouts/iframe.aspx    Line: 1

    Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.SharePoint.ApplicationPages' could not be loaded.

    Monday, February 16, 2009 10:30 PM
  • I think you actually want to check the DateTimeControl.isDateEmpty property to see if there is a date time in the control, and if there is then you can use the value. 

    http://www.novolocus.com/2009/02/24/notes-on-the-microsoftsharepointwebcontrolsdatetimecontrol/ 
    Tuesday, February 24, 2009 4:05 PM
  • Thanks Andy DateTimeControl.IsDateEmpty worked!
    Wednesday, April 22, 2009 1:12 PM
  • SOLUTION:

    The same issue, but in my case this check ( DateTimeControl.IsDateEmpty ) not work.
    Try to delete line where the ID of the DateTimeControl is set (sample):

    DateTimeControl.ID = "dt" + this.UniqueID;

    ...then now mantain selected date.

    Cheers!

    Monday, May 04, 2009 2:11 PM
  • Can someone please give me an example on how to implement the DateTimeControl.isDateEmpty property in SPD.  I have a simple form that updates an SQL database and can't figure out how to update the date field in the SQL database with a null or no date valule; because the DateTimeControl always returns today's date if the user clears the date field. 

    Thanks in advance for your help!
    Friday, May 29, 2009 4:40 PM
  • try this...

    before insert into database, put this code

    protected void lnkInsertInstitusi_StatusSP_Click(object sender, EventArgs e)
            {

                //dtTkhkuatkuasa
                Object objTkhkuatkuasa = DBNull.Value;

                if (dtTkhkuatkuasa.IsDateEmpty)
                {
                    objTkhkuatkuasa = DBNull.Value;
                }
                else
                {
                    objTkhkuatkuasa = dtTkhkuatkuasa.SelectedDate.ToString();
                }

    Tuesday, November 17, 2009 7:54 AM