데이터 처리/SQL

ISO 8601 - 타임스탬프를 문자열로 표현할 때 사용하는 포맷

yourhm 2025. 11. 18. 12:50

ISO 8601란?

: 타임스탬프(날짜&시간)를 문자열로 표현할 때 자주 쓰는 표준 포맷 중 하나

 

ISO → 국제 표준 만드는 기관 이름 (국제표준화기구, International Organization for Standardization)
8601 → 그 기관이 만든 “날짜 및 시간 표기 방식”에 붙인 표준 번호


즉, ISO가 만든 날짜 및 시간 표현 규격

 

대표 예시 의미
2025-11-18T12:34:56Z Z => UTC
2025-11-18T12:34:56+09:00 +09:00 => UTC+09:00 (한국 시간을 의미함)
2025-11-18T12:34:56.123456Z 마이크로초까지 표시한 경우

 

- 가운데 'T' 는 날짜(Date)와 시간(Time)을 구분하는 문자 (Time 의 약자)

- 날짜/시간을 한 줄로 이어 쓸 때 공백 대신 T를 쓰자고 정해둔 것.

 

 

 

DB에 타임스탬프가 어떻게 저장되어 있을까?

1. 화면에 보이는 형식 vs 내부 저장 방식

우리가 SELECT로 조회해서 볼 때는
→ 2025-11-18 21:00:00 이런 문자열 형태로 보이지만,

내부(디스크/메모리)에 저장될 때는
→ 숫자 기반의 이진 값으로 저장된다. (문자열로 그대로 저장 X)

 

 

2. BigQuery는 타임스탬프를 어떤 형태로 저장할까?

▶ 저장할 때는?

- 내부적으로 마이크로초 단위의 “유닉스 타임스탬프 스타일”로 저장 및 계산된다.

- 유닉스 타임스탬프란? 1970-01-01 00:00:00 UTC 이후 경과한 시간을 마이크로초 단위 정수로 표현한 값

 

대표적인 예시 유닉스 타임스탬프(마이크로초 단위)
1970-01-01T00:00:00Z 0
1970-01-01T00:00:01Z 1,000,000 (기준에서 1초 후)
1970-01-01T00:00:00.123456Z 123,456 (기준에서 0.123456초 후)
2020-01-01T00:00:00Z 1,577,836,800,000,000 (2020년 새해 0시 UTC)
2025-11-18T00:00:00Z 1,763,424,000,000,000 (2025년 11월 18일 0시 UTC)

 

 

  보여줄 때는?

BigQuery가 TIMESTAMP 값을 내부적으로 저장하는 방식은 일정하지만, 이 데이터를 읽어서 화면에 표시할 때는 일반적으로 다양한 사용자 인터페이스(UI)나 시스템 환경에 따라 표시 형식이 조금씩 달라질 수 있다. 왜냐하면 이들이 데이터를 어떤 형식으로 출력할지 결정하기 때문에. 그래도 ISO 8601이라는 큰 틀 안에서 날짜-시간 구분자(T 또는 공백), 시간대 표시 방법(UTC 또는 Z 또는 오프셋) 등이 조금씩 달라지는 정도다. 구현에 따라 형식이 달라지더라도 그레고리력 날짜, 시간, 시간대 정보는 필수적으로 포함된다. 

 

<구현에 따라 표시 형식 차이>

구현
(클라이언트/도구)
일반적인 표시 형식 특징
BigQuery 웹 UI
YYYY-MM-DD HH:MI:SS.nnnnnn UTC 가장 표준적이고 명확한 형식입니다. UI 설정에 따라 사용자 지역 시간대로 변환되어 보일 수도 있습니다.
BigQuery API 응답
YYYY-MM-DDTHH:MI:SS.nnnnnnZ 날짜와 시간 사이에 'T' 문자를 포함하는 엄격한 ISO 8601/ISO 3339 형식입니다. (대부분의 프로그래밍 언어에서 기본적으로 사용하는 형식)

 

이외에도 드라이버 및 연결된 애플리케이션(예: Tableau, Python, Java)의 설정에 따라 시간대가 생략되거나, 애플리케이션의 로컬 시간대로 자동 변환되는 등 다양한 형식으로 표시될 수 있다.

 

 

<BigQuery 웹 UI에서 TIMESTAMP 값을 표시하는 표준 형식>

YYYY-MM-DD HH:MI:SS.nnnnnn [time_zone]

 

이 형식이 BigQuery가 데이터를 출력할 때 사용하는 기본 틀이다. 만약 타임존이 명시되어 있지 않다면, 기본적으로 UTC를 의미한다. (the default time zone: UTC) -> 이 형식은 기본 틀일 뿐, 사용자가 정해진 규칙 안에서 변형할 수 있다. 예를 들어 아래 기본 형식에는 날짜와 시간 사이가 '공백'이지만, 규칙에 따라 공백 대신 'T'나 't' 문자를 넣는 것도 가능하다. 자세한 내용은 아래 빅쿼리 공식 문서 내용을 참고할 것.  

 

 

[참고]

BigQuery 공식문서: Data Types | TIMESTAMP

https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/data-types#timestamp_type

 

Data types  |  BigQuery  |  Google Cloud Documentation

Send feedback Data types Stay organized with collections Save and categorize content based on your preferences. This page provides an overview of all GoogleSQL for BigQuery data types, including information about their value domains. For information on dat

docs.cloud.google.com

BigQuery 공식문서: Lexical structure and syntax | TIMESTAMP LITERALS

https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/lexical#timestamp_literals

 

Lexical structure and syntax  |  BigQuery  |  Google Cloud Documentation

Send feedback Lexical structure and syntax Stay organized with collections Save and categorize content based on your preferences. A GoogleSQL statement comprises a series of tokens. Tokens include identifiers, quoted identifiers, literals, keywords, operat

docs.cloud.google.com

BigQuery 공식문서: How time zones work with timestamp functions

https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#timezone_definitions

 

Timestamp functions  |  BigQuery  |  Google Cloud Documentation

Send feedback Timestamp functions Stay organized with collections Save and categorize content based on your preferences. GoogleSQL for BigQuery supports the following timestamp functions. IMPORTANT: Before working with these functions, you need to understa

docs.cloud.google.com

BigQuery 공식문서: Datetime functions

https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/datetime_functions

 

Datetime functions  |  BigQuery  |  Google Cloud Documentation

Send feedback Datetime functions Stay organized with collections Save and categorize content based on your preferences. GoogleSQL for BigQuery supports the following datetime functions. All outputs are automatically formatted as per ISO 8601, separating da

docs.cloud.google.com

 

 

 

 

 

 

3. MySQL은 타임스탬프를 어떤 형태로 저장할까?

: 내부적으로 “유닉스 타임스탬프 스타일의 숫자”로 저장된다.

 

즉, 1970-01-01 00:00:00 UTC(유닉스 epoch) 를 기준으로 그 이후 경과한 초( + 선택적으로 마이크로초)를 나타내는 값으로 저장함.