[Vb.Net] Time and Dates Calculations

This set of functions enables to convert time and date into different units.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
'Author : Saadry Dunkel Consultant
'Date   : 20/03/2018


#Region "[Time and Dates]"
#Region "[Time and Dates] Increasing"
    ''' <summary>
    ''' Convert Milliseconds to Seconds
    ''' LOCATION > M_Info [Time and Dates] Increasing
    ''' </summary>
    ''' <param name="Milliseconds">Must be greater than 0</param>
    ''' <returns></returns>
    Public Function F_Convert_Milliseconds_ToSeconds(ByVal Milliseconds As Integer) As Integer
        Dim Result As Integer
        If Milliseconds > 0 Then
            Result = Milliseconds / 60
        Else
            Result = 0
        End If
        Return Result
    End Function
    ''' <summary>
    ''' Convert Seconds to Minutes
    ''' LOCATION > M_Info [Time and Dates] Increasing
    ''' </summary>
    ''' <param name="Seconds">Must be greater than 0</param>
    ''' <returns></returns>
    Public Function F_Convert_Seconds_ToMinutes(ByVal Seconds As Integer) As Integer
        Dim Result As Integer
        If Seconds > 0 Then
            Result = Seconds / 60
        Else
            Result = 0
        End If
        Return Result
    End Function
    ''' <summary>
    ''' Convert Minutes to Hours
    ''' LOCATION > M_Info [Time and Dates] Increasing
    ''' </summary>
    ''' <param name="Minutes">Must be greater than 0</param>
    ''' <returns></returns>
    Public Function F_Convert_Minutes_ToHours(ByVal Minutes As Integer) As Integer
        Dim Result As Integer
        If Minutes > 0 Then
            Result = Minutes / 60
        Else
            Result = 0
        End If
        Return Result
    End Function
    ''' <summary>
    ''' Convert Hours to Days
    ''' LOCATION > M_Info [Time and Dates] Increasing
    ''' </summary>
    ''' <param name="Hours">Must be greater than 0</param>
    ''' <returns></returns>
    Public Function F_Convert_Hours_ToDays(ByVal Hours As Integer) As Integer
        Dim Result As Integer
        If Hours > 0 Then
            Result = Hours / 24
        Else
            Result = 0
        End If
        Return Result
    End Function
    ''' <summary>
    ''' Convert Days to Week
    ''' LOCATION > M_Info [Time and Dates] Increasing
    ''' </summary>
    ''' <param name="Days">Must be greater than 0</param>
    ''' <returns></returns>
    Public Function F_Convert_Days_ToWeeks(ByVal Days As Integer) As Integer
        Dim Result As Integer
        If Days > 0 Then
            Result = Days / 0.142857
        Else
            Result = 0
        End If
        Return Result
    End Function
    ''' <summary>
    ''' Convert Weeks to Months
    ''' LOCATION > M_Info [Time and Dates] Increasing
    ''' </summary>
    ''' <param name="Weeks">Must be greater than 0</param>
    ''' <returns></returns>
    Public Function F_Convert_Weeks_ToMonths(ByVal Weeks As Integer) As Integer
        Dim Result As Integer
        If Weeks > 0 Then
            Result = Weeks / 0.22998418858703
        Else
            Result = 0
        End If
        Return Result
    End Function
    ''' <summary>
    ''' Convert Days to Months
    ''' LOCATION > M_Info [Time and Dates] Increasing
    ''' </summary>
    ''' <param name="Days">Must be greater than 0</param>
    ''' <returns></returns>
    Public Function F_Convert_Days_ToMonths(ByVal Days As Integer) As Integer
        Dim Result As Integer
        If Days > 0 Then
            Result = Days / 30.436875
        Else
            Result = 0
        End If
        Return Result
    End Function
    ''' <summary>
    ''' Convert Months to Years
    ''' LOCATION > M_Info [Time and Dates] Increasing
    ''' </summary>
    ''' <param name="Months">Must be greater than 0</param>
    ''' <returns></returns>
    Public Function F_Convert_Months_ToYears(ByVal Months As Integer) As Integer
        Dim Result As Integer
        If Months > 0 Then
            Result = Months / 12
        Else
            Result = 0
        End If
        Return Result
    End Function
#End Region
#Region "[Time and Dates] Decreasing"
    ''' <summary>
    ''' Convert Years to Months
    ''' LOCATION > M_Info [Time and Dates] Decreasing
    ''' </summary>
    ''' <param name="Years"></param>
    ''' <returns></returns>
    Public Function F_Convert_Years_ToMonths(ByVal Years As Integer) As Integer
        Dim Result As Integer
        Result = Years * 12
        Return Result
    End Function
    ''' <summary>
    ''' Convert Weeks to Days  
    ''' LOCATION > M_Info [Time and Dates] Decreasing
    ''' </summary>
    ''' <param name="Weeks"> </param>
    ''' <returns></returns>
    Public Function F_Convert_Weeks_ToDays(ByVal Weeks As Integer) As Integer
        Dim Result As Integer
        Result = Weeks * 7
        Return Result
    End Function
    ''' <summary>
    ''' Convert Months to Weeks  
    ''' LOCATION > M_Info [Time and Dates] Decreasing
    ''' </summary>
    ''' <param name="Months"> </param>
    ''' <returns></returns>
    Public Function F_Convert_Months_ToWeeks(ByVal Months As Integer) As Integer
        Dim Result As Integer
        Result = Months * 4.348125
        Return Result
    End Function
    ''' <summary>
    ''' Convert Months to Days
    ''' LOCATION > M_Info [Time and Dates] Decreasing
    ''' </summary>
    ''' <param name="Month"></param>
    ''' <returns></returns>
    Public Function F_Convert_Months_ToDays(ByVal Month As Integer) As Integer
        Dim Result As Integer
        Result = Month * 30.436875
        Return Result
    End Function
    ''' <summary>
    ''' Convert Days to Hours
    ''' LOCATION > M_Info [Time and Dates] Decreasing
    ''' </summary>
    ''' <param name="Days"></param>
    ''' <returns></returns>
    Public Function F_Convert_Days_ToHours(ByVal Days As Integer) As Integer
        Dim Result As Integer = 0
        Result = Days * 24
        Return Result
    End Function 'OK
    ''' <summary>
    ''' Convert Hours to Minutes
    ''' LOCATION > M_Info [Time and Dates] Decreasing
    ''' </summary>
    ''' <param name="Hours"></param>
    ''' <returns></returns>
    Public Function F_Convert_Hours_ToMinutes(ByVal Hours As Integer) As Integer
        Dim Result As Integer = 0
        Result = Hours * 60
        Return Result
    End Function 'OK
    ''' <summary>
    ''' Convert Minutes to Seconds
    ''' LOCATION > M_Info [Time and Dates] Decreasing
    ''' </summary>
    ''' <param name="Minutes"></param>
    ''' <returns></returns>
    Public Function F_Convert_Minutes_ToSeconds(ByVal Minutes As Integer) As Integer
        Dim Result As Integer = 0
        Result = Minutes * 60
        Return Result
    End Function 'OK
    ''' <summary>
    ''' Convert Seconds To Milliseconds
    ''' LOCATION > M_Info [Time and Dates] Decreasing
    ''' </summary>
    ''' <param name="Seconds"></param>
    ''' <returns></returns>
    Public Function F_Convert_Seconds_ToMilliseconds(ByVal Seconds As Integer) As Integer
        Dim Result As Integer = 0
        Result = Seconds * 60
        Return Result
    End Function 'OK
#End Region
#Region "[Time and Dates] To Timer"
    ''' <summary>
    ''' Convert Time to Milliseconds
    ''' LOCATION > M_Info [Time and Dates] To Timer
    ''' </summary>
    ''' <param name="Years"></param>
    ''' <param name="Months"></param>
    ''' <param name="Weeks"></param>
    ''' <param name="Days"></param>
    ''' <param name="Hours"></param>
    ''' <param name="Minutes"></param>
    ''' <param name="Seconds"></param>
    ''' <returns></returns>
    Public Function F_Convert_Time_ToTimer(Optional ByVal Years As Integer = 0,
                                           Optional ByVal Months As Integer = 0,
                                           Optional ByVal Weeks As Integer = 0,
                                           Optional ByVal Days As Integer = 0,
                                           Optional ByVal Hours As Integer = 0,
                                           Optional ByVal Minutes As Integer = 0,
                                           Optional ByVal Seconds As Integer = 0) As Integer
        Dim Result As Integer
        Dim MT As Integer
        Dim WK As Integer
        Dim DD As Integer
        Dim HH As Integer
        Dim MM As Integer
        Dim SS As Integer
        Dim MS As Integer
        MT = F_Convert_Years_ToMonths(Years) + Months
        WK = F_Convert_Months_ToWeeks(MT) + Weeks
        DD = F_Convert_Weeks_ToDays(WK) + Days
        HH = F_Convert_Days_ToHours(DD) + Hours
        MM = F_Convert_Hours_ToMinutes(HH) + Minutes
        SS = F_Convert_Minutes_ToSeconds(MM) + Seconds
        MS = F_Convert_Seconds_ToMilliseconds(SS)
        Result = MS
        Return Result
    End Function 'OK
#End Region
#Region "[Date] Find Last Day"
    Public Function Info_Find_LastDayOfMonth(intMonth, intYear) As Date
        Info_Find_LastDayOfMonth = DateSerial(intYear, intMonth + 1, 0)
    End Function

#End Region
#End Region

3607total visits,4visits today

Share with:
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Telephone

+41 (079) 5111570

Postal address

Saadry Dunkel
2 avenue des Amazones
1224 ChĂȘnes-Bougeries

Contact Us




All fields are required.


Sending...

Close contact form
UA-29636309-1