# How to check if the date is before today

**URL:** <https://discuss.workflowgen.com/t/how-to-check-if-the-date-is-before-today/1955>\
**Category:** General WorkflowGen Discussion\
**Created:** [October 11, 2021, 12:32pm UTC](https://discuss.workflowgen.com/t/how-to-check-if-the-date-is-before-today/1955 "2021-10-11T12:32:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElisaNPP](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@ElisaNPP](https://discuss.workflowgen.com/u/ElisaNPP)\
**Post date:** [October 11, 2021, 12:32pm UTC](https://discuss.workflowgen.com/t/how-to-check-if-the-date-is-before-today/1955/1 "2021-10-11T12:32:20Z")

</div>

Hello,

I would like to check if the date is before today. If not, a warning appears.

Thanks in advance

![Capture](https://canada1.discourse-cdn.com/flex030/uploads/workflowgen/original/1X/48b9c3e59a16756cdd0e23678d7e88cec11c6805.jpeg)

---

<div class="post-metadata">

**Author:** ![kevin.lee](https://avatars.discourse-cdn.com/v4/letter/k/65b543/32.png) [@kevin.lee](https://discuss.workflowgen.com/u/kevin.lee)\
**Post date:** [October 16, 2021, 1:54am UTC](https://discuss.workflowgen.com/t/how-to-check-if-the-date-is-before-today/1955/2 "2021-10-16T01:54:07Z")

</div>

You can try to do this in code behind (.NET)

```auto

     protected void Page_Load(object sender, EventArgs e)
	 {
	     base.Page_Load(sender, e);
	     
         //-- attach an event to the date picker so that whenever a date is selected it will trigger a validation
	     REQUEST_DATETIME_CAL.AutoPostBack = true;
		 REQUEST_DATETIME_CAL.DateChanged += ValidateDate;
	     
	 }

    protected void ValidateDate(object sender, EventArgs e)
    {
        DateTime UserDate;

            if (DateTime.TryParse(REQUEST_DATETIME.Text, out UserDate))
            {
                //--- check if selected date is before or on today's date
                if ((UserDate - System.DateTime.Today).TotalDays <= 0)
                {
                    //---- display the error message and reset the input if necessary
                    REQUEST_VALIDATE_MSG.Text = REQUEST_DATETIME.Text + " is invalid";
                    REQUEST_DATETIME.Text = ""; //--- reset input
                }
                else
                {   
                    //--- if the date is right, clear the message
                    REQUEST_VALIDATE_MSG.Text = "";   
                }
                
            }
        
    }

```

---

<div class="post-metadata">

**Author:** ![ElisaNPP](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@ElisaNPP](https://discuss.workflowgen.com/u/ElisaNPP)\
**Post date:** [October 20, 2021, 3:07pm UTC](https://discuss.workflowgen.com/t/how-to-check-if-the-date-is-before-today/1955/3 "2021-10-20T15:07:06Z")

</div>

Thank you Kevin! I found a solution one day before your answer and it’s quite similar 🙂
