如何比较给定天数之间的日期? [英] how to compare date between given days?
问题描述
大家好,
我要问一个问题对你们来说可能是一个非常简单的问题,但我无法解决。
我想比较输出天数之间的一个日期。
例如我的存储过程是:
Hi all,
I am going asking one question might be very easy question for u people but i am unable to solve it.
I want to compare one date between output days.
e.g. my stored procedure is:
select Emp_Name as Name, MA_Title as Sex, MA_Joining_Date as DOJ, Emp_Designation,
Working_From, Working_To, Interval_From, Interval_To, MA_LeaveTypeName as LeaveType, From_Date, To_Date from master_applicant
join
Master_Designation on MA_App_Code = Emp_Code
join
Working_Hours on MA_App_Code = Emp_Code
join
Applicant_Leave_Details on MA_App_Code = App_Code
join
master_LeaveType on LeaveType_ID = MA_LeaveTypeID
where From_Date between @StartDate and @EndDate
现在这里startDate& EndDate是:
now here startDate & EndDate is :
'2015-01-01' and '2015-01-31'
然后输出是:
then output is :
Name Sex DOJ Emp_Designation Working_From Working_To Interval_From Interval_To LeaveType From_Date To_Date
Olga Barretto NULL 2007-11-19 00:00:00.000 Assistant Manager 9 am 5 pm 12 pm 1 pm APL 2015-01-01 2015-01-06
Olga Barretto NULL 2007-11-19 00:00:00.000 Assistant Manager 9 am 5 pm 12 pm 1 pm APL 2015-01-16 2015-01-16
Olga Barretto NULL 2007-11-19 00:00:00.000 Assistant Manager 9 am 5 pm 12 pm 1 pm APL 2015-01-18 2015-01-18
Olga Barretto NULL 2007-11-19 00:00:00.000 Assistant Manager 9 am 5 pm 12 pm 1 pm APL 2015-01-18 2015-01-22
Olga Barretto NULL 2007-11-19 00:00:00.000 Assistant Manager 9 am 5 pm 12 pm 1 pm APL 2015-01-22 2015-01-22
Jagadeesh Tadimalla Mr 2011-04-05 00:00:00.000 Lead HSSE Advisor-Functional Compliance 9 am 5 pm 12 pm 1 pm APL 2015-04-14 2015-04-17
现在我想表明输出日期不存在,其他日期是以.aspx.cs格式开发的但是我无法联合约会:
我的代码是:
now i want to show that output date is in absent and other days are present for that i develop in .aspx.cs form but i unable to comapre date :
my code is:
string date1 = rds["From_date"].ToString();
if (date1 == "APL")
{
myrow["1"] = "APL";
}
else if (date1 == "SL")
{
myrow["1"] = "SL";
}
else if (date1 == "Maternity Leave")
{
myrow["1"] = "MATERNITY";
}
else if (date1 == "Paternity Leave")
{
myrow["1"] = "PATERNITY";
}
else if (date1 == "Without Pay Leave")
{
myrow["1"] = "Without Pay Leave";
}
else
{
myrow["1"] = "P";
}
推荐答案
我觉得你的意思是:
I think what you meant to write was:
string date1 = rds["LeaveType"].ToString();
if (date1 == "APL")
{
请考虑使用开关
块而不是if ... else for这 - 它更有效,更容易阅读/修改。
And please, consider using a switch
block rather than if...else for this - it's more efficient, and easier to read / modify.
这篇关于如何比较给定天数之间的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!