、「Dtを」RavenDBの日付と(YYYY/MM/DD形式) - 「/日のような「RELEASEDATE」(タイムスタンプ(11876.688億)/ ")。私は、クエリが正常に実行するために得ることができるので、このために私はほとんど仕事を取得し、次のコードを使用していますが、私が緩んで両端を完成させるために少しの助けを必要と...クエリで二つの異なる日付形式の比較私はユーザが入力した日付を比較する必要が
は、どのように私は2つの日付を比較することができます。
public ActionResult Calculation(DateTime? Dt)
{
var store = new DocumentStore { Url = "http://localhost:80" };
store.Initialize();
var CalcModel = new CalcViewModel();
using (var session = store.OpenSession())
{
//Converting user entered date dt in mm/dd/yyyy format to total
//milliseconds - So that later I can compare this value to RavenDB
//time stamp date format (older versions)
DateTime d1 = new DateTime(1970, 1, 1);
DateTime d2 = Dt.Value.ToUniversalTime();
TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks);
double tmillisecs = ts.TotalMilliseconds; //Not yet using this value.
CalcModel.MoviesByDate = session.Query<Movies>()
.Where(x => x.ReleaseDate.Ticks == ts.Ticks)
.Count();
// this is where I need to compare two dates - ts.ticks gives the
// required value of date (1187668800000) multiplied by 10000.
}
return View(CalcModel);
}
は今、私はデバッグするとき、私は...表示されているもの値ts.ticks知っていると私はコードのコメントに上記の言ったようにその、必要な値が10000を掛けしかし、私は、実行時見当もつかない時間、x.ReleaseDateの値は何か、x.ReleaseDate.Ticksは..これを正しくしていますか?助けてくれてありがとう。
あなたは.Where(X => x.ReleaseDates.Date == d2.Date)を意味し、d1.Dateありませんか?右?私はこのことであまり運がありませんでした。もう一度試してみましょう。ありがとうございました。 – ZVenue
@ZVenue - 日付が日付で、あなたにも時間を比較している場合を除き..時間が何であるかは関係.Dateの一部をオフに残し、その場合には、ユニバーサル時間を使用していないが(あなたがユニバーサルで日付時刻を入力すると仮定すると時間) –
はい..これは働いた。ありがとうございました。コードの行ですDateTime d2 = Dt.Value.ToUniversalTime();これを行うには重要です..または私はちょうどクエリで直接Dt(パラメータ値)を使用できますか? .Where(x => x.ReleaseDates.Date == dt.Date)のように。 – ZVenue