Propósito

✔ Programação GLOBAL® - Quaisquer soluções e/ou desenvolvimento de aplicações pessoais, ou da empresa, que não constem neste Blog devem ser tratados como consultoria freelance. Queiram contatar-nos: brazilsalesforceeffectiveness@gmail.com | ESTE BLOG NÃO SE RESPONSABILIZA POR QUAISQUER DANOS PROVENIENTES DO USO DOS CÓDIGOS AQUI POSTADOS EM APLICAÇÕES PESSOAIS OU DE TERCEIROS.

.: Vitrine

Carregando artigos...

Views

Mostrando postagens com marcador time. Mostrar todas as postagens
Mostrando postagens com marcador time. Mostrar todas as postagens

Excel Tips - Funções de Data e Tempo - Date and time functions

Inline image 1

Para utilizarmos bem as funções do MS Excel precisamos ao menos saber que existem e conhecermos onde as podemos aplicar.

O que segue são algumas destas que podemos utilizar extensivamente, agora com um pouco mais de conhecimento.

Tenham em mente que elas estão expressas em inglês, escolhi assim para que pudéssemos ter proveito delas tanto funcionalmente no MS Excel quanto na programação VBA. Sei que na maioria das empresas a instalação está em português, o que pessoalmente acho péssimo, nestes casos poderá procurar pela referência de como escrevê-la em Português.

Ahh e não reclamem, aproveitem para usar o Google Translate se precisarem.

Funções de Data e Tempo

DATE
Returns the serial number of a particular date

DATEVALUE
Converts a date in the form of text to a serial number

DAY
Converts a serial number to a day of the month

DAYS360
Calculates the number of days between two dates based on a 360-day year

EDATE
Returns the serial number of the date that is the indicated number of months before or after the start date

EOMONTH
Returns the serial number of the last day of the month before or after a specified number of months

HOUR
Converts a serial number to an hour

MINUTE
Converts a serial number to a minute

MONTH
Converts a serial number to a month

NETWORKDAYS
Returns the number of whole workdays between two dates

NOW
Returns the serial number of the current date and time

SECOND
Converts a serial number to a second

TIME
Returns the serial number of a particular time

TIMEVALUE
Converts a time in the form of text to a serial number

TODAY
Returns the serial number of today's date

WEEKDAY
Converts a serial number to a day of the week

WEEKNUM
Converts a serial number to a number representing where the week falls numerically with a year

WORKDAY
Returns the serial number of the date before or after a specified number of workdays

YEAR
Converts a serial number to a year

YEARFRAC
Returns the year fraction representing the number of whole days between start_date and end_date



Tags: Function, Excel, Tips, functions, Date, Time




VBA Tips - Demonstrar o tempo em Milisegundos - How to Get Time in Milliseconds using VBA


Saber expressar o tempo em milisegundos pode ser importante em qualquer  aplicação VBA. Como fazê-lo?

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Declare Sub GetSystemTime Lib "kernel32" _
(lpSystemTime As SYSTEMTIME)

Public Function TimeToMillisecond() As String
Dim tSystem As SYSTEMTIME
Dim sRet
On Error Resume Next
GetSystemTime tSystem
sRet = Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & _
":" & tSystem.wMilliseconds
TimeToMillisecond = sRet
End Function

Tags: Tips, milisegundos, miliseconds, API, LIB, kernel32, DLL, time, VBA, 

VBA Tips - Como converto números para horas?

bgHeaderClock2.png

Como no Access a exibição de horas é limitada (só vai até 23:59), é uma prática comum usar números Single nos cálculos. A exibição nos relatórios, porém, precisa ser no formato de horas.

Para converter um número Single para uma String no formato de horas, a seguinte função pode ser usada:

'************************************************** 
'Funções para se trabalhar com horas acima de 24h
'************************************************** 
Public Function HrStr (dblHora As Double) As String
'Pega um valor numérico e o converte para Horas/Minutos
'Ex: 123,5 = "123:30"
'Ex: 23,9833333333333 = "23:59"
Dim strHoras As String
Dim strMinutos As String
'Pega as horas (parte inteira)
strHoras = CStr(Fix(dblHora))
'Pega os minutos
strMinutos = Format$(Abs((dblHora - Fix(dblHora)) * 60), "00")
'Verifica se o total de minutos é 60
If strMinutos = "60" Then
strMinutos = "00"
strHoras = CStr(CDbl(strHoras) + 1)
End If
'Concatena os dois
HrStr = strHoras & ":" & strMinutos
End Function
Esta outra função faz o contrário: pega um string no formato de horas e converte para número:
Public Function HrDbl(stHora As String) As Double
'Converte um string de hora (formato (h)hh:mm) para Double
'Ex: "135:30" = 135,5
'Ex: "23:59" = 23,9833333333333
Dim dblHoras As Double
Dim intMinutos As Integer
Dim blnDoisPontos As Boolean, blnNum As Boolean
Dim strNum As String
'Verifica se o sinal de dois pontos ':' está na terceira casa
'da direita para esquerda
If Asc(Left(Right(stHora, 3), 1)) = 58 Then
    blnDoisPontos = True
Else
    blnDoisPontos = False
End If
'Verifica se o resto dos dígitos são numéricos
strNum = Left(stHora, Len(stHora) - 3) & Right(stHora, 2)
If IsNumeric(strNum) = True Then
    blnNum = True
Else
    blnNum = False
End If
'Sai do procedimento se o formato estiver incorreto
If (blnDoisPontos = False) Or (blnNum = False) Then
    MsgBox "Informe a hora no formato hh:mm", vbCritical + vbOKOnly
    Exit Function
End If
'Pega os minutos
If CDbl(strNum) < 0 Then
    intMinutos = CInt(Right(strNum, 2)) * (-1)
Else
    intMinutos = CInt(Right(strNum, 2))
End If
'Pega as horas
dblHoras = Fix(CDbl(Left(strNum, Len(strNum) - 2)))
'Calcula a hora
HrDbl
= dblHoras + (intMinutos / 60)
End Function 


Tags
Microsoft Office, VBA, tips, convert, hour, hora, clock, time

André Luiz Bernardes
A&A® - Work smart, not hard.


diHITT - Notícias