Gestione date

lunedì 24 novembre 2008 - 00.16

camposeo79 Profilo | Junior Member

Salve a tutti.
Vi spiego il mio prob.
Ho la necessità di capire in VB6 che giorno è (sabato, domenica etc) una certa data inserita. Che ne so, magari mediante l'utilizzo di qualche oggetto del tipo dtpicker etc...

Grazie a tutti.

Giuseppe.

Dainesi Profilo | Senior Member

La funzione che ti interessa si chiama WeekDay e riporta un numero che corrisponde al giorno della settimana. Per tradurre il giorno unsa WeekDayName

La prima si usa così:

Dim i as Integer
Dim strDay as String
Dim dData as Date

dData = CalendarControl1.Value
i = Weekday(dData, [firstdayweek]) 'se firstdayweek è vbMonday (2) allora la settimana inizia con il lunedì se non metti nulla inizia di domenica
strDay = WeekdayName(i, false, [firstdayweek]) 'Stesse considerazioni come sopra. Il parametro di mezzo indica se vuoi l'abbreviazione o no.

MsgBox "Il giorno " & Format(dData, "DD/MM/YYYY") & " è " & strDay

camposeo79 Profilo | Junior Member

Grazie mille....

ps: Sicuramente chiederò troppo, ma c'è un modo per vedere se una determinata data è festivo, senza fare un controllo a mano?

Dainesi Profilo | Senior Member

Per festivo cosa intendi ? Sabato e Domenica o anche le feste comandate, Pasqua e lunedì dell'Angelo ?

camposeo79 Profilo | Junior Member

beh il sabato e domenica riesco a farlo tranquillamente con con il metodo weekday che mi hai consigliato precedentemente, intendevo per festivi i giorni tipo natale pasqua etc..

Dainesi Profilo | Senior Member

Beh ... Natale è sempre il 25 Dicembre e così pure S.Stefano, San Silvestro e via dicendo.
Ti basta testare con un bel Select:

Select case Month(dTest)

Case = 1: If Day(dTest) = 1 Or Day(dTest) = 6 then ...'Festa
Case = 4: If Day(dTest) = 25 then ...
...

End Select

L'unica festa che crea grattacapi è la Pasqua. Questa viene calcolata ricorrendo ad un antico algoritmo così:

Function Pasqua(ByVal dTest As Date) As Date

Dim d
Dim m
Dim y

d = 0
m = 0
y = Year(dTest)

Dim g 'golden Year - 1
Dim c 'century
Dim h ' = (23 - Epact) mod 30
Dim i 'no of Days from March 21 to Paschal Full Moon
Dim j 'WeekDay for PFM (0=Sunday, etc)
Dim p 'no of Days from March 21 to Sunday on or before PFM
'(-6 to 28 methods 1 & 3, to 56 for method 2)
Dim e 'extra Days to add for method 2 (converting Julian date to Gregorian date)

g = y Mod 19

c = y \ 100
h = (c - c \ 4 - (8 * c + 13) \ 25 + 19 * g + 15) Mod 30
i = h - (h \ 28) * (1 - (h \ 28) * (29 \ (h + 1)) * ((21 - g) \ 11))
j = (y + y \ 4 + i + 2 - c + c \ 4) Mod 7

'return Month
p = i - j + e
' p can be from -6 to 56 corresponding to dates 22 March to 23 May
' (later dates apply to method 2, although 23 May never actually occurs)
d = 1 + (p + 27 + (p + 6) \ 40) Mod 31
m = 3 + (p + 26) \ 30

Pasqua = dTest
Pasqua = DateAdd("M", -Month(Pasqua) + 1, Pasqua)
Pasqua = DateAdd("D", -Day(Pasqua) + 1, Pasqua)
Pasqua = DateAdd("h", -Hour(Pasqua), Pasqua)
Pasqua = DateAdd("n", -Minute(Pasqua), Pasqua)
Pasqua = DateAdd("s", -Second(Pasqua), Pasqua)

Pasqua = DateAdd("M", m - 1, Pasqua)
Pasqua = DateAdd("d", d - 1, Pasqua)

End Function

Function AngelDay(ByVal dTest As Date) As Boolean

'Questa funzione ritorna TRUE se la data passata coincide con il Lunedì dell'Angelo. La data di Pasqua è ricavata con l'apposita formula
Dim dP

dP = Pasqua(dTest)
dP = DateAdd("d", 1, dP)

If dTest = dP Then
AngelDay = True
Else
AngelDay = False
End If

End Function

camposeo79 Profilo | Junior Member

thanks....

Dainesi Profilo | Senior Member

Altro che thanks ... se va bene Accetta!
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5