linq을 사용하여 제공된 날짜보다 & 시간이 큰 레코드 만 반환하려고합니다. 레코드의 날짜와 시간은 문자열 형식의 다른 열에 있습니다. (예 : 29/Aug/2011)의 경우 "290811"이고 사용되는 상황에 따라 오후 2 또는 14 시간의 경우 "1400"입니다.Linq의 날짜 및 시간을 비교하는 C#
은 내가 무슨 짓을 :
var result = from s in source
where GetDateTime(s.date, s.time) >= myDateTime
select s;
GetDateTime
내가 날짜 시간 형식으로 날짜와 시간을 반환하도록 만든 기능입니다. myDatetime
은 제가 전달하는 날짜입니다.
편집 : 기능은 사용 :
public static DateTime GetDateTime(string strDate, string strTime) {
DateTime dt;
int dd = Convert.ToInt32(strDate.Substring(0, 2));
int mm = Convert.ToInt32(strDate.Substring(2, 2));
int yy = Convert.ToInt32("20" + strDate.Substring(4, 2));
TimeSpan ts = GetTimeFromString(strTime);
dt = new DateTime(yy, mm, dd, ts.Hours, ts.Minutes, 0);
return dt;
}
public static TimeSpan GetTimeFromString(string strTime) {
int hh = Convert.ToInt32(strTime.Substring(0, 2));
int mins = Convert.ToInt32(strTime.Substring(2, 2));
return new TimeSpan(hh, mins, 0);
}
샘플 데이터 :
이Adt_avlStatus 7
Adt_BaseFare 100
Adt_breakPoint Y
Adt_cabin M
Adt_Discount 0
Adt_Farebasis EAP14DN
Adt_fareType RP
Adt_Markup 0
Adt_rbd E
date 290811
time 1520
Origin IXC
Destination GOI
myDateTime
샘플 : 20/08/2011 17:35:00
(20/2,011 8월은 5:35 PM /)
문제는 위의 linq가 결과를 필터링하지 않는다는 것입니다. 내가 뭘 잘못하고 있는지 말해줘. 감사.
'GetDateTime()'의 구현을 보여주세요. –
당신은 무엇을하고 있는지 모른 채 어떻게 당신을 돕고 싶습니까? –
'GetDateTime' 함수가 추가되었습니다. –