comparing two dates

4 posts, 1 answers
  1. BRK
    BRK avatar
    35 posts
    Member since:
    Jun 2012

    Posted 28 Mar 2011 Link to this post


    Hi Folks,

    I slowed down at comparing two dates in Rad Grid. Here the comparison includes GridDateTimeColumn and  GridTemplateColumn.
    Can I compare them both with dates involved or I need to change them.below I am giving the tags.Please help me out to solve this.

    <telerik:GridDateTimeColumn UniqueName="schedstart" DataField="early_start_display" HeaderText="Scheduled Start" DataFormatString="{0:MM/dd/yyyy}" PickerType="DatePicker" AllowFiltering="false"> </telerik:GridDateTimeColumn>
     
     
     
    <telerik:GridTemplateColumn UniqueName="gridMS" HeaderText="Mandatory Start" AllowFiltering="false">
                         <ItemTemplate>
                           <telerik:RadDatePicker ID="manstart" runat="server" Width="100px" Calendar-ShowOtherMonthsDays="false" Calendar-ShowRowHeaders="false" MinDate='<%# Convert.ToDateTime(Eval("early_start_display")).ToString("dd/MMM/yyyy") %>' DbSelectedDate='<%# Bind("mandatory_start") %>' DateInput-DateFormat="MM/dd/yyyy"/>
                         </ItemTemplate>
                        </telerik:GridTemplateColumn>
  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 28 Mar 2011 Link to this post

    <telerik:GridDateTimeColumn UniqueName="schedstart" DataField="CreatedDate" HeaderText="CreatedDate"
                                  DataFormatString="{0:MM/dd/yyyy}" PickerType="DatePicker" AllowFiltering="false">
                              </telerik:GridDateTimeColumn>
                              <telerik:GridTemplateColumn UniqueName="gridMS" HeaderText="Mandatory Start" AllowFiltering="false">
                                  <ItemTemplate>
                                      <telerik:RadDatePicker ID="manstart" runat="server" Width="100px" Calendar-ShowOtherMonthsDays="false"
                                          Calendar-ShowRowHeaders="false" MinDate='<%# Convert.ToDateTime(Eval("CreatedDate")) %>'
                                          DbSelectedDate='<%# Bind("LastUpdatedDate") %>' DateInput-DateFormat="MM/dd/yyyy" />
                                  </ItemTemplate>

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
     
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = (GridDataItem)e.Item;
                 
                RadDatePicker manstart = (RadDatePicker)dataItem.FindControl("manstart");
                DateTime schedstart = DateTime.ParseExact(dataItem["schedstart"].Text, "MM/dd/yyyy", null);
     
                // comapre both dates
                if (manstart.SelectedDate < schedstart)
                {
                    dataItem["schedstart"].Text = "01/01/2010"; //set new date
                    manstart.SelectedDate = DateTime.Now; //set new date
                }
            }
    }
    Hi brk,

    let me know if any concern

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. BRK
    BRK avatar
    35 posts
    Member since:
    Jun 2012

    Posted 28 Mar 2011 Link to this post

    Thanks Jayesh Now I have one more problem is that.

    I have two dates 1) Start Date 2) Finish date

    and the condition is
    we Cannot enter Finish date lesser than or equal to START date.

    Please help on that
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 28 Mar 2011 Link to this post

    hi brk,

    <script type="text/javascript">
        var datePicker2;
        function DateSelected(sender, args) {
     
            var startDate = sender.get_selectedDate();
     
     
           
     
            if (datePicker2.get_selectedDate() == null) {
                datePicker2.set_selectedDate(startDate);
            }
     
            if (datePicker2.get_selectedDate() < sender.get_selectedDate()) {
                datePicker2.set_selectedDate(startDate);
            }
     
        }
        function onClientLoadHandler(sender, args) {
            datePicker2 = sender;
        }
    </script>

    <telerik:GridTemplateColumn HeaderText="Start Date" UniqueName="HoldiayStartDate"
                                   HeaderStyle-HorizontalAlign="Left" GroupByExpression="HoldiayStartDate Group By HoldiayStartDate"
                                   SortExpression="HoldiayStartDate">
                                   <EditItemTemplate>
                                       <telerik:RadDatePicker ID="dpHoldiayStartDate" runat="server" DbSelectedDate='<%# Bind("HoldiayStartDate", "{0:d}") %>'
                                           SharedCalendarID="" MinDate="1900/01/01" ZIndex="10000000" DateInput-DateFormat="dd/MM/yyyy">
                                           <ClientEvents OnDateSelected="DateSelected" />
                                       </telerik:RadDatePicker>
                                       <asp:RequiredFieldValidator ID="rfvHoldiayStartDate" runat="server" ErrorMessage='<%$Resources:HolidayResources ,HolidayDateValidate %>'
                                           ControlToValidate="dpHoldiayStartDate" Display="Dynamic"></asp:RequiredFieldValidator>
                                   </EditItemTemplate>
                                   <ItemTemplate>
                                       <asp:Label ID="lblHoldiayStartDate" runat="server" Text='<%# Eval("HoldiayStartDate", "{0:d}") %>' />
                                   </ItemTemplate>
                                   <ItemStyle Width="20%" HorizontalAlign="Left" />
                               </telerik:GridTemplateColumn>
                               <telerik:GridTemplateColumn HeaderText="End Date" UniqueName="HolidayEndDate" HeaderStyle-HorizontalAlign="Left"
                                   GroupByExpression="HolidayEndDate Group By HolidayEndDate" SortExpression="HolidayEndDate">
                                   <EditItemTemplate>
                                       <telerik:RadDatePicker ID="dpHolidayEndDate" runat="server" DbSelectedDate='<%# Bind("HolidayEndDate", "{0:d}") %>'
                                           SharedCalendarID="" MinDate="1900/01/01" ZIndex="10000000" DateInput-DateFormat="dd/MM/yyyy">
                                           <DateInput ID="DateInput1" runat="server">
                                               <ClientEvents OnLoad="onClientLoadHandler" />
                                           </DateInput>
                                       </telerik:RadDatePicker>
                                       <asp:RequiredFieldValidator ID="rfvHolidayEndDate" runat="server" ErrorMessage='<%$Resources:HolidayResources ,HolidayDateValidate %>'
                                           ControlToValidate="dpHolidayEndDate" Display="Dynamic"></asp:RequiredFieldValidator>
                                       <asp:CompareValidator ID="cvEndDate" runat="server" Display="Dynamic" SetFocusOnError="true"
                                           ControlToValidate="dpHolidayEndDate" ControlToCompare="dpHoldiayStartDate" Type="Date"
                                           Operator="GreaterThanEqual" ErrorMessage='<%$Resources:HolidayResources ,EndDateValidate %>'></asp:CompareValidator>
                                   </EditItemTemplate>
                                   <ItemTemplate>
                                       <asp:Label ID="lblHolidayEndDate" runat="server" Text='<%# Eval("HolidayEndDate", "{0:d}") %>' />
                                   </ItemTemplate>
                                   <ItemStyle Width="20%" HorizontalAlign="Left" />
                               </telerik:GridTemplateColumn>

    let me know if any concern

    Thanks,
    Jayesh Goyani
Back to Top