본문 바로가기
VBA 라이브러리

FormatDateTime 함수

2023. 8. 23.

FormatDateTime 함수

 

날짜와 시간으로 서식이 지정된 식을 반환합니다.

Syntax
FormatDateTime(Date, [ NamedFormat ])

 

Date : 필수입니다. 서식을 지정할 날짜표현식입니다.

NamedFormat : 선택 사항입니다. 사용된 날짜/시간 형식을 나타내는 숫자값.이 값을 생략하면 vbGeneralDate가 사용됩니다.

 

설정
NamedFormat 인수 설정은 아래와 같습니다.

 

다음 코드는 FormatDateTime 함수의 사용 방법을 보여줍니다.

Public Function FormatDateTimeCustom(ByVal dateTimeValue As Date, ByVal dateFormatType As VbDateTimeFormat) As String
    FormatDateTimeCustom = FormatDateTime(dateTimeValue, dateFormatType)
End Function

Sub TestFormatDateTime()
    Dim dateTimeValue As Date
    dateTimeValue = Now

    Debug.Print "일반 날짜 형식: " & FormatDateTimeCustom(dateTimeValue, vbGeneralDate)
    Debug.Print "긴 날짜 형식: " & FormatDateTimeCustom(dateTimeValue, vbLongDate)
    Debug.Print "짧은 날짜 형식: " & FormatDateTimeCustom(dateTimeValue, vbShortDate)
    Debug.Print "긴 시간 형식: " & FormatDateTimeCustom(dateTimeValue, vbLongTime)
    Debug.Print "짧은 시간 형식: " & FormatDateTimeCustom(dateTimeValue, vbShortTime)
End Sub

' Output
' 일반 날짜 형식: 8/23/2023 10:50:09 AM
' 긴 날짜 형식: Wednesday, August 23, 2023
' 짧은 날짜 형식: 8/23/2023
' 긴 시간 형식: 10:50:09 AM
' 짧은 시간 형식: 10:50

 

도움말 출처

 

 

FormatDateTime function (Visual Basic for Applications)

Office VBA reference topic

learn.microsoft.com

'VBA 라이브러리' 카테고리의 다른 글

FormatPercent 함수  (0) 2023.08.23
FormatNumber 함수  (0) 2023.08.23
FormatCurrency 함수  (0) 2023.08.22
Format 함수  (0) 2023.08.22
GetObject 함수  (0) 2023.08.06