문제

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")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top