Date question

  • Thread starter Thread starter simon
  • Start date Start date
S

simon

If you have dateTime value, for example: 08.04.1004 11:00:00

how do you get how many seconds is until midnight.

The reggional settings shouldnt affect on this.

Thank you,
Simon
 
I havent tried this but it might work.

Public Function SecsToMidnight(ByVal dIn As DateTime) As Long
If Now.Hour = 0 And Now.Minute = 0 And Now.Second = 0 Then
Return 0
End If
Dim dMidNight, dTest As DateTime
dMidNight = Now.AddDays(1)
dMidNight = CDate(dMidNight.ToString("dd-MMM-yyyy 00:00:00"))
dTest = CDate(dMidNight.ToString("dd-MMM-yyyy ") & dTest.ToString("HH:mm:ss"))
Return Math.Abs(DateDiff(DateInterval.Second, dMidNight, dIn))
End Function
 
const d as date = #4/8/2004 11:00#
dim diff as double

diff = d.date.adddays(1).subtract(d).totalseconds

Do I think I give the same answer as Armin did (today or yesterday) comes
Armin with a very nice solutions.

:-)

Cor
 
Back
Top