Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to save date details into table with half day working as 0.5 days between two given dates.
I'm using checkbox for both from date and to date.
I want to save 0.5 day in table if checkbox checked for start or end date.
For example:
From date 10/02/2018 AN
To date 12/02/2018

i want to save in table like
date days
10/02/2018 0.5
11/02/2018 1
12/02/2018 1

What I have tried:

Im using while loop to get individual date details from given two dates.
Posted
Updated 12-Feb-18 9:14am
Comments
Ziee-M 12-Feb-18 7:50am    
Post your code.
Ashokk88 13-Feb-18 0:22am    
DateTime t1 = Convert.ToDateTime(txt_from_date.Text);
DateTime t2 = Convert.ToDateTime(txt_to_date.Text);
double comp_days;
while (t1 <= t2)
{
...insert into table code....
t1 = t1.AddDays(1);
}


I want to add half day details if user select the respective check box.
OriginalGriff 12-Feb-18 8:05am    
And?
What have you tried?
Where are you stuck?
What help do you need?
Ashokk88 13-Feb-18 0:24am    
DateTime t1 = Convert.ToDateTime(txt_from_date.Text);
DateTime t2 = Convert.ToDateTime(txt_to_date.Text);
double comp_days;
while (t1 <= t2)
{
...insert into table code....
t1 = t1.AddDays(1);
}


I want to add half day details if user select the respective check box.
Ashokk88 13-Feb-18 1:33am    
I want to save day as 0.5 if from date or to date is half day only.
For example-
From date 13/02/2018 (half day selected)
To date 15/02/2018
In my table i want to save like for date 13/02/2018 as 0.5 and
(14/02/2018, 15/02/2018) as 1

1 solution

Please check my answer to similar question: How to fill a series of date using start date and end date in C#[^]

All you need to do is to change

SQL
CREATE PROCEDURE uspInsertDateRange
--input variables
    @startDate DATE,
    @isStartDateHalfDay BIT,
    @endDate DATE,
    @isEndDateHalfDay BIT
AS
--a content of SP here
...


How to pass parameters into stored procedure in ASP.NET?
SqlDataSource StoredProcedure example: Pass parameters to StoredProcedure using SqlDataSource in ASP.Net[^]
How to: Set and Get Parameters for Command Objects[^]
How to call SQL Server stored procedures in ASP.NET by using Visual Basic .NET[^]

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900