FormatDateTime 함수

형식이 지정된 표현식을 날짜 또는 시간으로 반환합니다.

구문

FormatDateTime(Date[,NamedFormat])

인수:

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

    주:

    • 문자열이 입력으로 제공된 경우 입력 날짜 및 시간에 사용되는 구분자는 시스템 특정 로케일 구분자와 동일해야 합니다. 이 이미지 정크 문자의 특수 문자는 지원되지 않습니다.
    • 일수는 입력 인수로 지정되지 않아야 하며 지원되지 않습니다.
    • 날짜, 월 및 연도는 완전한 형식으로 작성되어야 합니다. 예를 들어, 08/02/2024에서 8/2/24와 같은 약식 형식은 지원되지 않습니다.
  • NamedFormat: 선택사항. 사용된 날짜 및 시간 형식을 나타내는 숫자 값입니다. 생략할 경우 vbGeneralDate가 사용됩니다. 값은 설정 섹션을 참조하십시오.

Settings: NamedFormat 인수의 설정은 다음과 같습니다.

vbGeneralDate: 일반 날짜 형식의 날짜를 가져오려면 값을 0으로 전달합니다.

날짜 및/또는 시간을 표시합니다. 날짜 부분이 있는 경우 해당 부분을 short형 날짜로 표시합니다. 시간 부분이 있는 경우 해당 부분을 Long형 시간으로 표시합니다. 있는 경우 두 부분이 모두 표시됩니다.

예 1:

Dim d, mytime
d="12/19/2024"
mytime = FormatDateTime(d,0)    
'Output: 12/19/2024 12:00:00 AM

d="12/19/2024 02:30 PM"
mytime = FormatDateTime(d,0)            
'Output: - 12/19/2024 02:30:00 PM

d="14:30:10 12/19/2024"
mytime = FormatDateTime(d,0)    
'Output: - 12/19/2024 02:30:10 PM

d="02:30 PM 12/19/2024"
mytime = FormatDateTime(d,0)
'Output: - 12/19/2024 02:30:00 PM

d="12/19/2024 2pm"
mytime = FormatDateTime(d,0)    
Output: - 12/19/2024 02:00:00 PM

d="2 pm"
mytime = FormatDateTime(d,0)
'Output: - 12/30/1899 02:00:00 PM

d="12-19-2024"
mytime = FormatDateTime(d,0)
'Output: - ERROR as delimiter should be same as locale’s delimiter

vbLongDate: Long Date Pass Value 1을 가져옵니다.

컴퓨터의 지역 설정에 지정된 Long형 날짜 형식을 사용하여 날짜를 표시합니다.

주:

Long형 날짜는 영어 문자로만 내용을 표시하고 평일 구문 분석은 지원되지 않습니다.

예 2:

Dim d, mytime
d="12/19/2024"
mytime = FormatDateTime(d,1)    
'Output: 12/19/2024 12:00:00 AM

d="12/19/2024 02:30 PM"
mytime = FormatDateTime(d,1)            
'Output: - 12/19/2024 02:30:00 PM

d="14:30:10 12/19/2024"
mytime = FormatDateTime(d,1)    
'Output: - 12/19/2024 02:30:10 PM

d="02:30 PM 12/19/2024"
mytime = FormatDateTime(d,1)
'Output: - 12/19/2024 02:30:00 PM

d="12/19/2024 2pm"
mytime = FormatDateTime(d,1)    
Output: - 12/19/2024 02:00:00 PM

d="2 pm"
mytime = FormatDateTime(d,1)
'Output: - 12/30/1899 02:00:00 PM

d="12-19-2024"
mytime = FormatDateTime(d,1)
'Output: - ERROR as delimiter should be same as locale’s delimiter

vbShortDate: Short Date Pass Value 2를 가져옵니다.

컴퓨터의 지역 설정에 지정된 날짜 형식을 사용하여 날짜를 표시합니다.

예 3:

Dim d, mytime
d="12/19/2024"
mytime = FormatDateTime(d,2)    
'Output: 12/19/2024 12:00:00 AM

d="12/19/2024 02:30 PM"
mytime = FormatDateTime(d,2)            
'Output: - 12/19/2024 02:30:00 PM

d="14:30:10 12/19/2024"
mytime = FormatDateTime(d,2)    
'Output: - 12/19/2024 02:30:10 PM

d="02:30 PM 12/19/2024"
mytime = FormatDateTime(d,2)
'Output: - 12/19/2024 02:30:00 PM

d="12/19/2024 2pm"
mytime = FormatDateTime(d,2)    
Output: - 12/19/2024 02:00:00 PM

d="2 pm"
mytime = FormatDateTime(d,2)
'Output: - 12/30/1899 02:00:00 PM

d="12-19-2024"
mytime = FormatDateTime(d,2)
'Output: - ERROR as delimiter should be same as locale’s delimiter

vbLongTime: Long Time Format Pass Value 3의 시간을 가져옵니다.

컴퓨터의 지역 설정에 지정된 시간 형식을 사용하여 시간을 표시합니다.

주:

Long형 시간은 AM 또는 PM과 같이 영문자로만 내용을 표시합니다.

예 4:

Dim d, mytime
d="12/19/2024"
mytime = FormatDateTime(d,3)    
'Output: 12/19/2024 12:00:00 AM

d="12/19/2024 02:30 PM"
mytime = FormatDateTime(d,3)            
'Output: - 12/19/2024 02:30:00 PM

d="14:30:10 12/19/2024"
mytime = FormatDateTime(d,3)    
'Output: - 12/19/2024 02:30:10 PM

d="02:30 PM 12/19/2024"
mytime = FormatDateTime(d,3)
'Output: - 12/19/2024 02:30:00 PM

d="12/19/2024 2pm"
mytime = FormatDateTime(d,3)    
Output: - 12/19/2024 02:00:00 PM

d="2 pm"
mytime = FormatDateTime(d,3)
'Output: - 12/30/1899 02:00:00 PM

d="12-19-2024"
mytime = FormatDateTime(d,3)
'Output: - ERROR as delimiter should be same as locale’s delimiter

vbShortTime: Short Time Format Pass Value 4의 시간을 가져옵니다.

시간을 24시간 형식(hh:mm)을 사용하여 표시합니다.

예 5:

Dim d, mytime
d="12/19/2024"
mytime = FormatDateTime(d,4)    
'Output: 12/19/2024 12:00:00 AM

d="12/19/2024 02:30 PM"
mytime = FormatDateTime(d,4)            
'Output: - 12/19/2024 02:30:00 PM

d="14:30:10 12/19/2024"
mytime = FormatDateTime(d,4)    
'Output: - 12/19/2024 02:30:10 PM

d="02:30 PM 12/19/2024"
mytime = FormatDateTime(d,4)
'Output: - 12/19/2024 02:30:00 PM

d="12/19/2024 2pm"
mytime = FormatDateTime(d,4)    
Output: - 12/19/2024 02:00:00 PM

d="2 pm"
mytime = FormatDateTime(d,4)
'Output: - 12/30/1899 02:00:00 PM

d="12-19-2024"
mytime = FormatDateTime(d,4)
'Output: - ERROR as delimiter should be same as locale’s delimiter