MaxGekk commented on a change in pull request #27830: [SPARK-31030][SQL] Backward Compatibility for Parsing and formatting Datetime URL: https://github.com/apache/spark/pull/27830#discussion_r389006226
########## File path: docs/sql-ref-datetime-pattern.md ########## @@ -0,0 +1,212 @@ +--- +layout: global +title: Datetime patterns +displayTitle: Datetime Patterns for Formatting and Parsing +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +Spark uses the blow letters in date and timestamp parsing and formatting: +<table class="table"> +<tr> + <th> <b>Symbol</b> </th> + <th> <b>Meaning</b> </th> + <th> <b>Presentation</b> </th> + <th> <b>Examples</b> </th> +</tr> +<tr> + <td> <b>G</b> </td> + <td> era </td> + <td> text </td> + <td> AD; Anno Domini; A </td> +</tr> +<tr> + <td> <b>y</b> </td> + <td> year </td> + <td> year </td> + <td> 2020; 20 </td> +</tr> +<tr> + <td> <b>D</b> </td> + <td> day-of-year </td> + <td> number </td> + <td> 189 </td> +</tr> +<tr> + <td> <b>M</b> </td> + <td> month-of-year </td> + <td> number/text </td> + <td> 7; 07; Jul; July; J </td> +</tr> +<tr> + <td> <b>d</b> </td> + <td> day-of-month </td> + <td> number </td> + <td> 28 </td> +</tr> +<tr> + <td> <b>Y</b> </td> + <td> week-based-year </td> + <td> year </td> + <td> 1996; 96 </td> +</tr> +<tr> + <td> <b>w</b> </td> + <td> week-of-week-based-year </td> + <td> number </td> + <td> 27 </td> +</tr> +<tr> + <td> <b>W</b> </td> + <td> week-of-month </td> + <td> number </td> + <td> 4 </td> +</tr> +<tr> + <td> <b>E</b> </td> + <td> day-of-week </td> + <td> text </td> + <td> Tue; Tuesday; T </td> +</tr> +<tr> + <td> <b>e</b> </td> + <td> localized day-of-week </td> + <td> number/text </td> + <td> 2; 02; Tue; Tuesday; T </td> +</tr> +<tr> + <td> <b>F</b> </td> + <td> week-of-month </td> + <td> number </td> + <td> 3 </td> +</tr> +<tr> + <td> <b>a</b> </td> + <td> am-pm-of-day </td> + <td> text </td> + <td> PM </td> +</tr> +<tr> + <td> <b>h</b> </td> + <td> clock-hour-of-am-pm (1-12) </td> + <td> number </td> + <td> 12 </td> +</tr> +<tr> + <td> <b>K</b> </td> + <td> hour-of-am-pm (0-11) </td> + <td> number </td> + <td> 0 </td> +</tr> +<tr> + <td> <b>k</b> </td> + <td> clock-hour-of-am-pm (1-24) </td> + <td> number </td> + <td> 0 </td> +</tr> +<tr> + <td> <b>H</b> </td> + <td> hour-of-day (0-23) </td> + <td> number </td> + <td> 0 </td> +</tr> +<tr> + <td> <b>m</b> </td> + <td> minute-of-hour </td> + <td> number </td> + <td> 30 </td> +</tr> +<tr> + <td> <b>s</b> </td> + <td> second-of-minute </td> + <td> number </td> + <td> 55 </td> +</tr> +<tr> + <td> <b>S</b> </td> + <td> fraction-of-second </td> + <td> fraction </td> + <td> 978 </td> +</tr> +<tr> + <td> <b>z</b> </td> + <td> time-zone name </td> + <td> zone-name </td> + <td> Pacific Standard Time; PST </td> +</tr> +<tr> + <td> <b>O</b> </td> + <td> localized zone-offset </td> + <td> offset-O </td> + <td> GMT+8; GMT+08:00; UTC-08:00; </td> +</tr> +<tr> + <td> <b>X</b> </td> + <td> zone-offset 'Z' for zero </td> + <td> offset-X </td> + <td> Z; -08; -0830; -08:30; -083015; -08:30:15; </td> +</tr> +<tr> + <td> <b>x</b> </td> + <td> zone-offset </td> + <td> offset-x </td> + <td> +0000; -08; -0830; -08:30; -083015; -08:30:15; </td> +</tr> +<tr> + <td> <b>Z</b> </td> + <td> zone-offset </td> + <td> offset-Z </td> + <td> +0000; -0800; -08:00; </td> +</tr> +<tr> + <td> <b>'</b> </td> + <td> escape for text </td> + <td> delimiter </td> + <td></td> +</tr> +<tr> + <td> <b>''</b> </td> + <td> single quote </td> + <td> literal </td> + <td> ' </td> +</tr> +</table> + +The count of pattern letters determines the format. + +- Text: The text style is determined based on the number of pattern letters used. Less than 4 pattern letters will use the short form. Exactly 4 pattern letters will use the full form. + +- Number: If the count of letters is one, then the value is output using the minimum number of digits and without padding. Otherwise, the count of digits is used as the width of the output field, with the value zero-padded as necessary. The following pattern letters have constraints on the count of letters. Only one letter 'F' can be specified. Up to two letters of 'd', 'H', 'h', 'K', 'k', 'm', and 's' can be specified. Up to three letters of 'D' can be specified. + +- Number/Text: If the count of pattern letters is 3 or greater, use the Text rules above. Otherwise use the Number rules above. + +- Fraction: Outputs the nano-of-second field as a fraction-of-second. The nano-of-second value has nine digits, thus the count of pattern letters is from 1 to 9. If it is less than 9, then the nano-of-second value is truncated, with only the most significant digits being output. Review comment: Currently, Spark doesn't support fraction in nanosecond precision. It can mislead users. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
