How we can get date in between in asp.net
we want to know how we can get date in between means if posting date is 09/04/2014 and exam date is 09/08/2014 so how we can use between keyword in two dates in asp.net
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sivaraman DhamodaranRank #40 · 34.5K reputationPosted Apr 1, 2014, 10:16 PM EDT
Are asking how do we use that in SQL Queries? Please elaborate your question
sudheer kumarRank #6,677 · 259 reputationPosted Apr 1, 2014, 10:32 PM EDT
Abhay ShankerRank #375 · 6.7K reputationPosted Apr 2, 2014, 1:25 AM EDT
dt1=09/04/2014
dt2=09/08/2014
if yes then at first you need to find the days between dates as below
(dt2-dt1).TotalDays (say 4)
then for getting a date add days to date
dt1.AddDays (1)
Note:-need to add a condition which would check here that added date must be less than difference of two dates
VulpesRank #55 · 29.2K reputationPosted Apr 2, 2014, 1:53 AM EDT
public static bool IsBetween(DateTime start, DateTime end, DateTime test)
{
if (test >= start && test <= end) return true;
return false;
}
For example:
DateTime start = new DateTime(2014, 1, 1);
DateTime end = new DateTime(2014, 5, 1);
bool isBetween = IsBetween(start, end, DateTime.Today);
Response.Write(isBetween.ToString()); // True