cs_SiLverFoX
Messages postés4Date d'inscriptiondimanche 16 juin 2002StatutMembreDernière intervention18 septembre 2002
-
18 juin 2002 à 22:30
borntoclimb
Messages postés98Date d'inscriptionvendredi 4 janvier 2002StatutMembreDernière intervention 7 mars 2006
-
19 juin 2002 à 00:24
comment je fais pour soustraire une date avec la date de la journé actuelle et meme chose pour l'heure .
ex: 30 - 18 qui eat la date de aujourd'hui et demin 30 - 19 vous voyez
borntoclimb
Messages postés98Date d'inscriptionvendredi 4 janvier 2002StatutMembreDernière intervention 7 mars 20064 19 juin 2002 à 00:24
J'ai le module suivant, peux être y trouveras ton bonheur.
Borntoclimb
'==============================================================================
'
' Date routines for PB/DLL
' Copyright (c) 1996 by PowerBASIC, Inc. All Rights Reserved.
'
' Note: All routines expect dates have been changed from the U.S. format.
' For international support, all you need to do is modify the
' SplitDate(), MakeDate()
' routines to support your specified format. All other routines
' call these routines to get the component parts.
'
' All dates used must be between 01-01-1900 and 06-05-2079
'
' If you pass a null (zero-length) string to a given routine,
' the current date/time is used.
'
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'
' CDOW - Return the name for the Day of the Week of a date
' DOW - Return the day of the week for a given date
' DOY - Return the day of the year for a given date
' DateMath - Add/Subtract days to a given date
' DateToDays - Convert a date into the number of days since 1900
' Days - Return the number of days between two dates
' DaysToDate - Convert the number of days since 1900 into a date
' Leap - Check a year to see if it's a leap year
' MakeDate - Create a date string from month, day, and year
' MonthName - Return the name of a given month
' SplitDate - Split a date into its component parts
' ValidDate - Check a date to see if it's valid
'
'==============================================================================
'===========================================================================
' SplitDate - Split a date passed in a string to its Month, Day, and Year
' components.
'
' Note: All other date routines call this routine to get the
' component parts.
'
' InDate = Date string in format (DD-MM-YY)
' Month = Returns the month
' Day = Returns the day of the month
' Year = Returns the year
'
Public Sub SplitDate(InDate As String, Month As Integer, Day As Integer, Year As Integer)
If Len(InDate) = 0 Then
InDate = Date$
End If
Month = Val(Mid$(InDate, 4, 2))
Day = Val(Mid$(InDate, 1, 2))
Year = Val(Mid$(InDate, 7, 2))
If Year < 80 Then ' assume we've rolled into the next century
Year = Year + 2000
ElseIf Year < 100 Then ' between 80 and 99, use this century
Year = Year + 1900
End If
End Sub
'===========================================================================
' MakeDate - Combine the component parts of a date into a displayable
' string in format DD/MM/YY.
'
' Note: All other date routines call this routine to combine
' the component parts.
'
Sub MakeDate(ByVal Month As Integer, ByVal Day As Integer, ByVal Year As Integer, lpStr As String)
Dim TmpStr As String
If Year < 80 Then 'assume we've rolled into the next century
Year = Year + 2000
ElseIf Year < 100 Then 'between 1980 and 1999
Year = Year + 1900
End If
'===========================================================================
' Leap - Return a one (1) if specified year is a leap year.
'
' Year = year to check
'
Public Function Leap(ByVal Year As Integer) As Integer
If (Year Mod 400) = 0 Then ' leap century
Leap = 1
ElseIf (Year Mod 100) = 0 Then
Leap = 0
ElseIf (Year Mod 4) = 0 Then ' leap year
Leap = 1
End If
End Function
'===========================================================================
' DaysInMonth - Return the number of days in a given month. It does not
' account for leap years.
'
' Month = month to return number of days
'
Public Function DaysInMonth(ByVal Month As Integer) As Integer
Dim Buff As String
Buff = "312831303130313130313031"
If (Month > 0) And (Month < 13) Then
DaysInMonth = Val(Mid$(Buff, 1 + (Month - 1) * 2, 2))
End If
End Function
'===========================================================================
' DateToDays - Convert the specified date into the number of days since
' 01-01-1900. Supports dates up to 06-05-2079.
'
' InDate = Date to convert
'
Public Function DateToDays(InDate As String) As Long
Dim Buffer As String
Dim Temp As Long
Dim z As Integer
Dim Month As Integer
Dim Day As Integer
Dim Year As Integer
If (Month > 2) Then
Temp = Temp + Leap(Year)
End If
Temp = Temp + Day
DateToDays = Temp
End Function
'===========================================================================
' DaysToDate - Convert the number of days since 01-01-1900 to a date string.
'
' NumDays = number of days since 1900
'
Public Sub DaysToDate(ByVal NumDays As Integer, RetVal As String)
Dim Month As Integer
Dim Year As Integer
Dim DaysInMnth As Integer
Dim DaysInYear As Integer
Dim TmpStr As String
Year = 1900
DaysInYear = 365 + Leap(Year)
Do Until (NumDays < DaysInYear)
NumDays = NumDays - (365 + Leap(Year))
Year = Year + 1
DaysInYear = 365 + Leap(Year)
Loop
For Month = 1 To 12
DaysInMnth = DaysInMonth(Month)
If Month = 2 Then
DaysInMnth = DaysInMnth + Leap(Year)
End If
If NumDays <= DaysInMnth Then
Exit For
End If
NumDays = NumDays - DaysInMnth
Next
If NumDays = 0 Then
Month = 12
NumDays = 31
Year = Year - 1
End If
MakeDate Month, NumDays, Year, RetVal
End Sub
'===========================================================================
' DateMath - Add the specified number of days the specified date.
' To subtract days, use a negative value.
'
' InDate = starting date
' NumberOfDays = number of days to add
'
Public Sub DateMath(InDate As String, ByVal NumberOfDays As Integer, _
RetVal As String)
'===========================================================================
' Days - Return the number of days between two dates. If the first date
' comes after the second date, a negative value is returned.
'
' Date1 = starting date
' Date2 = ending date
'
Public Function Days(Date1 As String, Date2 As String) As Integer
Days = DateToDays(Date1) - DateToDays(Date2)
End Function
'===========================================================================
' ValidDate - Returns true (-1) if the specified date is valid, or false (0)
' if the date is invalid.
'
' InDate = date to check
'
Public Function ValidDate(InDate As String) As Integer
Dim Month As Integer
Dim Day As Integer
Dim Year As Integer
Dim TotalDays As Integer
If Len(InDate) = 0 Then
Exit Function
End If
SplitDate InDate, Month, Day, Year
If (Month < 1) Or (Month > 12) Then
Exit Function
End If
TotalDays = DaysInMonth(Month)
If Month = 2 Then
TotalDays = TotalDays + Leap(Year)
End If
If (Day < 1) Or (Day > TotalDays) Then
Exit Function
End If
If Year < 1900 Then
Exit Function
End If
ValidDate = -1
End Function
'===========================================================================
' DOW - Return the Day of the Week as an integer.
'
' InDate = date to convert into the day of the week
'
Public Function DOW(InDate As String) As Integer
DOW = 1 + DateToDays(InDate) Mod 7
End Function
'===========================================================================
' DOY - Return the Day of the Year
'
' InDate = date to convert into day of the year
'
Public Function DOY(InDate As String) As Integer
Dim Month As Integer
Dim Day As Integer
Dim Year As Integer
Dim Buffer As String
Dim Temp As Integer
'===========================================================================
' CDOW - Return the name for the Day of the Week for the specified date.
'
' InDate = Date to return day of week name
'
Public Sub CDOW(InDate As String, RetVal As String)
'===========================================================================
' MonthName - Return the name for a specified month.
'
' Month = month to return name
'
Public Sub MonthName(ByVal Month As Integer, RetVal As String)