set date variable to 8pm last night
-
29-09-2019 - |
문제
Hi I'm wanting to set a variable date in the format Y-m-d 20:00:00 of the previous day. can someone help?
해결책
Dim lastNight As DateTime = DateTime.Today.AddHours(-4)
Dim lastNightString As String = lastNight.ToString("y-M-d HH:mm:ss")
다른 팁
There's probably an easier way but this is how I would probably do it in C#:
DateTime myDate = DateTime.Today.AddHours(20 - DateTime.Today.Hour).AddMinutes(0 - DateTime.Today.Minute).AddSeconds(0 - DateTime.Today.Second).AddMilliseconds(0 - DateTime.Today.Millisecond);
Then for formatting find something along the lines of: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
Try
Dim lastEvening as DateTime = DateTime.Today.AddDays(-1).AddHours(20)
Formatted as asked
Dim formattedLastEvening as string = lastEvening.ToString("y-M-d HH:mm:ss")
제휴하지 않습니다 StackOverflow