date_format doesn't handle timestamp with `00:00:00`

Kamel

It formats 2020-01-27 00:00:00 of type timestamp as 2020-01-27 12:00:00 instead of 2020-01-27 00:00:00

  import spark.sqlContext.implicits._
  import java.sql.Timestamp
import org.apache.spark.sql.functions.typedLit


scala>   val stamp = typedLit(new Timestamp(1580105949000L))
stamp: org.apache.spark.sql.Column = TIMESTAMP('2020-01-27 00:19:09.0')


scala>   var df_test = Seq(5).toDF("seq").select(
     |     stamp.as("unixtime"),
     |     date_trunc("HOUR", stamp).as("date_trunc"),
     |     date_format(date_trunc("HOUR", stamp), "yyyy-MM-dd hh:mm:ss").as("hour")
     |   )
df_test: org.apache.spark.sql.DataFrame = [unixtime: timestamp, date_trunc: timestamp ... 1 more field]


scala> df_test.show
+-------------------+-------------------+-------------------+
|           unixtime|         date_trunc|               hour|
+-------------------+-------------------+-------------------+
|2020-01-27 00:19:09|2020-01-27 00:00:00|2020-01-27 12:00:00|
+-------------------+-------------------+-------------------+
ernest_k

Your pattern should be yyyy-MM-dd HH:mm:ss.

date_format, according to its documentation, uses specifiers supported by java.text.SimpleDateFormat:

Converts a date/timestamp/string to a value of string in the format specified by the date format given by the second argument.
See SimpleDateFormat for valid date and time format patterns.

SimpleDateFormat's documentation can be found here

hh is used for "Hour in am/pm (1-12)". You're looking for the hour in day specifier, which is HH.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get date with 00:00:00 timestamp

MySQL DATE_FORMAT from '1970-01-01T00:00:00Z' to '1970-01-01 00:00:00'

Doctrine2 default timestamp wtih "0000-00-00 00:00:00" format?

R: Converting date/time format 0000-00-00T00:00:00Z to POSIXct

Cannot convert '0000-00-00 00:00:00' to TIMESTAMP

0000-00-00 00:00:00 in timestamp

set time to 00:00:00 doesn't work - java

How can I use datetime.strptime on a string in the format '0000-00-00T00:00:00+00:00'?

Store timestamp with time 00:00:00

Converting Timestamp to Month without the 00:00:00

PHP get 00:00:00 of a unix timestamp

Postgres timestamp not accepting 2017-01-01T23:00:00-00:00

Date format in javascript with time 00:00:00

Why does parsing "0000:00:00 00:00:00" into a Date return -0001-11-28T00:00:00Z?

Stopwatch/countdown (00:00:00) format with Javascript

Convert posixct time format into 00:00:00

Oracle - to_date() parse of 00:00:00

Convert 2020-09-01T00:00:00-05:00 timestamp to dd-mm-yyyy

how to change date format 2021-30-06T05:00:00+07:00 in swift?

Date pattrern format of 2021-02-22T00:00:00

''00:00'' format in textField (Flutter)

Mysql import transforms timestamp null values to 0000-00-00 00:00:00

'0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error

Firebase Database Rule that compares timestamp to 00:00:00 of today?

Converting chr "00:00:00" to date-time "00:00:00"

how to trim a date to format of 00/00/0000?

Pandas: group with 10T but to have a 00:11:00 format

yyyy-MM-ddT00:00:00 date format in MDX

convert Date format like this Fri Apr 20 2020 00:00:00 GMT+0530 (India Standard Time) to 2020-04-20T00:00:00.000Z in Javascript

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive