Hi
I have FROM DATE and TO DATE textbox on page. I want to validate textbox where User is allow to enter only 7 days date range in both textboxes. For Ex. If date in FROM DATE textbox is 10/07/2023, then TO DATE must be 17/07/2023 and If TO DATE changes then accordingly FROM DATE should be -7 days back.
User should not allow to choose more than 7 days in both textbox, and should see data between only 7 days
Thanks
Jayraj ChhayaPosted Dec 26, 2023, 9:26 AM
To validate the 7-day date range in C#, you can use the
DateTimeclass and some simple logic. Here's an example of how you can achieve this:To automatically adjust the "FROM DATE" when the "TO DATE" changes, you can use an event handler for the "TO DATE" textbox's
TextChangedevent. Here's an example:By using these code snippets, you can ensure that the user can only enter a 7-day date range in both textboxes and automatically adjust the "FROM DATE" when the "TO DATE" changes.
Subarta RayPosted Dec 26, 2023, 6:59 AM
To restrict users to a 7-day date range, use JavaScript. On TO DATE change, set FROM DATE to 7 days earlier, and vice versa. Example:
Anandu G NathPosted Dec 20, 2023, 7:09 AM
@Sushant Torankar
Anandu G NathPosted Dec 20, 2023, 7:09 AM
Try Below Code
Amit MohantyPosted Jul 26, 2023, 7:49 AM
Hey Sushant, try the below sample code.
ASPX Page:
Page_Load event:
Vishal JoshiPosted Jul 26, 2023, 4:41 AM
Hello Sushant,
try the below sample code to get difference between two dates in C#
ASPX Page code:
C# Code
Thanks
Tahir AnsariPosted Jul 26, 2023, 2:41 AM
Try