Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to find Date differences(dd/mm/yyyy)?

How to find Date differences(dd/mm/yyyy)?

Scheduled Pinned Locked Moved ASP.NET
helpcsstutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    irkahc
    wrote on last edited by
    #1

    Hi all, there are two textboxes in my page. FromDate and ToDate. dates are selected from popup calender and displayed in respective textboxes. when I click on a button, have to satisfy the following conditions.It is working with MM/dd/yyyy format.. but when I change the format to dd/mm/yyyy getting error.. 1. Difference between FromDate and ToDate sholud not greater than 31. 2. FromDate should be less than ToDate. 3. ToDate is not greater than current date. below is the code I had written: This code is working fine with MM/dd/yyyy date format.. but when I give the date in dd/mm/yyyy getting error. TimeSpan tsDaysDifference = Convert.ToDateTime(txtToDate.Text).Subtract(Convert.ToDateTime(txtFromDate.Text)); if (tsDaysDifference.Days > ConInterfaceManagerCommon.DATE_RANGE) { StringBuilder strbldrErrorScript = new StringBuilder(""); strbldrErrorScript.Append("alert('Difference between from and to dates should not morethan 31')"); strbldrErrorScript.Append(""); ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", strbldrErrorScript.ToString()); return false; } else if (tsDaysDifference.Days < ConInterfaceManagerCommon.DATE_MINIMUM) { StringBuilder strbldrErrorScript = new StringBuilder(""); strbldrErrorScript.Append("alert('From date should be lessthan todate')"); strbldrErrorScript.Append(""); ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", strbldrErrorScript.ToString()); return false; } else if (Convert.ToDateTime(txtToDate.Text) > DateTime.Now) { StringBuilder strbldrErrorScript = new StringBuilder(""); strbldrErrorScript.Append("alert('To date should be lessthan current date.')"); strbldrErrorScript.Append(""); ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", strbldrErrorScript.ToString()); return false; } else return true; Can anyone help how to find the date difference in dd/mm/yyyy format on serverside? Many Thanks

    J 1 Reply Last reply
    0
    • I irkahc

      Hi all, there are two textboxes in my page. FromDate and ToDate. dates are selected from popup calender and displayed in respective textboxes. when I click on a button, have to satisfy the following conditions.It is working with MM/dd/yyyy format.. but when I change the format to dd/mm/yyyy getting error.. 1. Difference between FromDate and ToDate sholud not greater than 31. 2. FromDate should be less than ToDate. 3. ToDate is not greater than current date. below is the code I had written: This code is working fine with MM/dd/yyyy date format.. but when I give the date in dd/mm/yyyy getting error. TimeSpan tsDaysDifference = Convert.ToDateTime(txtToDate.Text).Subtract(Convert.ToDateTime(txtFromDate.Text)); if (tsDaysDifference.Days > ConInterfaceManagerCommon.DATE_RANGE) { StringBuilder strbldrErrorScript = new StringBuilder(""); strbldrErrorScript.Append("alert('Difference between from and to dates should not morethan 31')"); strbldrErrorScript.Append(""); ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", strbldrErrorScript.ToString()); return false; } else if (tsDaysDifference.Days < ConInterfaceManagerCommon.DATE_MINIMUM) { StringBuilder strbldrErrorScript = new StringBuilder(""); strbldrErrorScript.Append("alert('From date should be lessthan todate')"); strbldrErrorScript.Append(""); ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", strbldrErrorScript.ToString()); return false; } else if (Convert.ToDateTime(txtToDate.Text) > DateTime.Now) { StringBuilder strbldrErrorScript = new StringBuilder(""); strbldrErrorScript.Append("alert('To date should be lessthan current date.')"); strbldrErrorScript.Append(""); ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", strbldrErrorScript.ToString()); return false; } else return true; Can anyone help how to find the date difference in dd/mm/yyyy format on serverside? Many Thanks

      J Offline
      J Offline
      Jim Conigliaro
      wrote on last edited by
      #2

      When converting to a datetime object, you need to specify the format of the date if you are giving it a format other than the default for the server. Your server is expecting mm/dd/yyyy, so if you want to specify a different date format, you will need to tell the ToDateTime function what format you are providing the data in.

      Jim Conigliaro jconigliaro@ieee.org
      http://www.jimconigliaro.com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups