-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTime.sql
More file actions
52 lines (28 loc) · 1.08 KB
/
Time.sql
File metadata and controls
52 lines (28 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
-- Databricks notebook source
-- MAGIC %md #### Get current timestamp
-- COMMAND ----------
select current_timestamp()
-- COMMAND ----------
-- MAGIC %md #### Lets check the timezone
-- COMMAND ----------
-- MAGIC %python
-- MAGIC spark.conf.get("spark.sql.session.timeZone")
-- COMMAND ----------
-- MAGIC %md So we see that by default it was UTC, which is the same as Zulu.We can easly change a timezone:
-- COMMAND ----------
-- MAGIC %python
-- MAGIC spark.conf.set("spark.sql.session.timeZone","Europe/Warsaw")
-- COMMAND ----------
-- MAGIC %md And our currect_timestamp will give us different results:
-- COMMAND ----------
select current_timestamp()
-- COMMAND ----------
-- MAGIC %md #### Now lets see UNIX time
-- COMMAND ----------
select unix_timestamp()
-- COMMAND ----------
-- MAGIC %md #### Converting UNIX time to human readable timestamp
-- COMMAND ----------
select cast(unix_timestamp() as timestamp)
-- COMMAND ----------
-- MAGIC %md By default it will convert to timestamp according to zulu. Unless you have set up a timezone, like we have done this above.