MSDN dice:
Quando altritipi di dati numerici vengono convertiti in Date, i valori a sinistra della virgola decimale rappresentano le informazioni relative alla data, mentre i valori a destra della virgola rappresentano l'orario. Mezzanotte corrisponde a 0 e mezzogiorno a 0,5. I numeri interi negativi rappresentano le date antecedenti al 30 dicembre 1899.
Allora io ho fatto questa prova:
codice:
Dim test1 As Date
Dim test2 As Date
test1 = CDate("08.45.00")
test2 = CDate("09.15.00")
test1 = DateAdd("n", 30, test1)
MsgBox test1 & " = " & test2 & " ? " & (test1 = test2)
Naturalmente il risultato è erratico.
codice:
Dim test1 As Date
Dim test2 As Date
test1 = CDate("09.00.00")
test2 = CDate("09.30.00")
test1 = DateAdd("n", 30, test1)
MsgBox test1 & " = " & test2 & " ? " & (test1 = test2)
Qui fa giusto.
perchè?
MSDN ci dice che la parte intera della data convertita rappresenta la data vera e propria mentre i decimali rappresentano l'orario.
quindi (in teoria) se tu fai date + 1 aggiungi un giorno e date + 0.5 aggiungi 12 ore.
Si vede che l'ora 9.15.00 convertita rappresenta un numero (double?) periodico, VB si intorta e non riesce a fare il confronto nella maniera corretta. 9.30 rappresenta un numero non periodico...
C'è di più. Se tu non fai la dateadd
codice:
Dim test1 As Date
Dim test2 As Date
test1 = CDate("09.15.00")
test2 = CDate("09.15.00")
MsgBox test1 & " = " & test2 & " ? " & (test1 = test2)
funziona!
Quindi la colpa potrebbe essere della dateadd che pone qualche bit in maniera sbagliata (IMHO of course).
Questo è interessante:
The Date Data Type
Date and time values can be contained both in the specific Date data type and in Variant variables. The same general characteristics apply to dates in both types.
For More Information___See the section, "Date/Time Values Stored in Variants," in "Advanced Variant Topics."
When other numeric data types are converted to Date, values to the left of the decimal represent date information, while values to the right of the decimal represent time. Midnight is 0, and midday is 0.5. Negative whole numbers represent dates before December 30, 1899.
...
Comunque, perchè non usi la funzione DateDiff?
codice:
Dim test1 As Date
Dim test2 As Date
test1 = CDate("08.45.00")
test2 = CDate("09.15.00")
test1 = DateAdd("n", 30, test1)
MsgBox test1 & " = " & test2 & " ? " & (DateDiff("n", test1, test2) = 0)
Funziona egregiamente...
La settimana prossima diggo un po' di più in MSDN perchè a quest'ora, di sabato, sono abbastanza cotto