C# - How To Check If Date Is Less Than or Equals To Today's Date - Stack Overflow
C# - How To Check If Date Is Less Than or Equals To Today's Date - Stack Overflow
- Stack Overflow
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in
the 2019 Developer Survey.
today's date?
Code:
class Program
{
public static bool IsDateBeforeOrToday(string input)
{
bool result = true;
if(input != null)
{
DateTime dTCurrent = DateTime.Now;
int currentDateValues = Convert.ToInt32(dTCurrent.ToString("MMddyyyy"));
int inputDateValues = Convert.ToInt32(input.Replace("/", ""));
return result;
}
c#
https://stackoverflow.com/questions/29258169/how-to-check-if-date-is-less-than-or-equals-to-todays-date 1/4
4/10/2019 c# - How to check if date is less than or equals to today's date? - Stack Overflow
asked Mar 25 '15 at 14:14
Asynchronous
1,749 14 51 78
4 Answers
Use DateTime.TryParseExact if
you want to avoid exception in
parsing.
Use DateTime.Today if you only
want to compare date and
ignore the time part.
https://stackoverflow.com/questions/29258169/how-to-check-if-date-is-less-than-or-equals-to-todays-date 2/4
4/10/2019 c# - How to check if date is less than or equals to today's date? - Stack Overflow
Implementation:
class Program
{
public static bool IsDateBeforeOr
{
DateTime inputTime;
var parseResult = DateTime.Tr
if (!parseResult)
//Do something useful if
return inputTime <= DateTime.
}
https://stackoverflow.com/questions/29258169/how-to-check-if-date-is-less-than-or-equals-to-todays-date 3/4
4/10/2019 c# - How to check if date is less than or equals to today's date? - Stack Overflow
https://stackoverflow.com/questions/29258169/how-to-check-if-date-is-less-than-or-equals-to-todays-date 4/4