Year/Month/Day... how to do

Asked

Viewed 95 times

0

but I need him to manage me a portfolio of year, month and day Can someone help me? follow...

' informacoes 
Public cDay, cMonth, cMonthName, cPath

Function identificarData()

' Identificar o caminho na rede

    cPath = "caminho para salvar o arquivo"

' Identificar o dia e mês

    If Day(Date) < 10 Then

        cDay = "0" & Day(Date)

    Else

        cDay = Day(Date)

    End If

    If Month(Date) + 1 < 10 Then

        cMonth = "0" & Month(Date)

    Else

        cMonth = Month(Date)

    End If

' Identificar o nome do mês

    Select Case cMonth

    Case Is = "01"
        cMonthName = "January"

    Case Is = "02"
        cMonthName = "February"

    Case Is = "03"
        cMonthName = "March"

    Case Is = "04"
        cMonthName = "April"

    Case Is = "05"
        cMonthName = "May"

    Case Is = "06"
        cMonthName = "June"

    Case Is = "07"
        cMonthName = "July"

    Case Is = "08"
        cMonthName = "August"

    Case Is = "09"
        cMonthName = "September"

    Case Is = "10"
        cMonthName = "October"

    Case Is = "11"
        cMonthName = "November"

    Case Is = "12"
        cMonthName = "December"

    End Select

End Function

1 answer

0


Follow a demo code of how to generate the month and day for a specific year. I suggest running step-by-step code to understand it (with F8 key).

Code

Dim Ano As Date, Data As Date
Dim i As Long, DiasNoMes As Long, j As Long
Ano = 2018
j = 0
'Teste Imprimir Meses
For i = 1 To 12
    Debug.Print DateSerial(Ano, i, 1) 'Ou
    'MsgBox DateSerial(Ano, i, 1)
    'Usar Debug.Print ou MsgBox
    Debug.Print Format(DateSerial(Ano, i, 1), "MMMM")

    'Dias no mês
    DiasNoMes = Day(DateSerial(Ano, i + 1, 0))
    Debug.Print DiasNoMes

    'Loop para criar cada dia do mês
    For j = 1 To DiasNoMes
        Debug.Print j
        Debug.Print DateSerial(Ano, i, j)
    Next j
Next i

Explanation

  • Insert 2018 as year: Ano = 2018
  • Loop in the 12 months of the year: For i = 1 To 12:Next i
  • The date of the first day of the month of the loop in the dd/mm/yyyy format: Debug.Print DateSerial(Ano, i + 1, 0)
  • The month written in full: Debug.Print Format(DateSerial(Ano, i, 1), "MMMM")
  • The number of days of the month: DiasNoMes = Day(DateSerial(Ano, i + 1, 0))
  • Loop on each day of the month: For j = 1 To DiasNoMes:Next j

Note: To view what is printed with the command Debug.Print, you need to enable the Immediate Verification dialog.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.