/

Date and Time Formats in LibreOffice Calc

1442 views
24

Date and Time formats and how they are represented in LibreOffice Calc is explained in this tutorial.

Date Formats

Open a blank Calc sheet and enter the below items – a date, a time and a date-time.

“3/2/2018”

“6:00”

“3/2/2018 6:00”

Once you entered, Calc would reformat them as below using default Calc formatting for each type.

Date Time Data
Date Time Data

Dates are stored as numbers in Calc and each day represents a number counted from the date Dec 12, 1899. However, you can change it from the menu Tools -> Options -> LibreOffice Calc -> Calculate. See below.

Default-date-calculation-Calc
Default-date-calculation-Calc

Right click on the date at A1 cell and click Format Cells. The default format of the selected cell would open up as below.

Format Cells-DD-MM-YY
Format Cells-DD-MM-YY

Convert the date to number

To convert the date to a number, simply choose Category=Number and you can see the numeric representation of the date. For this example 3/2/2018 is converted to the number 43134 which is nothing but the number of days elapsed from Jan 0, 1900.

Format Cells-Date Numbers

Format Cells-Date Numbers

Time and Conversion

If you apply the same i.e. format cells to numbers to the Time and Date Time as well you can see below results.

Converted to Number-All
Converted to Number-All

Time is represented in a scale of 0 to 1. So 6:00 AM is converted to .25 i.e. quarter of 24.

Custom Formatting of Date, Time

Calc provides a pre-defined set of date formats for general usage which you can access from the Format list below. However, if you want to customize your own format you can use any of the codes below and create your own custom format.

SEE ALSO:  How to find out empty, blank cells or rows in LibreOffice Calc

To create a custom format, right-click any cell and open up Format Cells dialog. In that dialog, start editing the Format Code (red arrow below). Once you start modifying it, you can see a “user-defined” category is automatically created. Now you can modify your format according to your needs. Refer to format codes at the end of this article.

You can also rename the category = “User-defined” by clicking a small note icon (blue arrow below) and click the tick button to Add.

Format Cells-Custom Format
Format Cells-Custom Format

In this example, we have applied the custom date format and it is applied to cell A1 below. It is worth to notice that though the representation is changed to “03/02/18Y”, the underlying value remains “03/02/2018”.

Custom Format Applied to a Date
Custom Format Applied to a Date

The same principle can be applied to Time formats as well.

List of Date Format Codes

Below are the format codes for dates that you can use in formatting cells.

FormatFormat Code
Month as 3.M
Month as 03.MM
Month as Jan-DecMMM
Month as January-DecemberMMMM
First letter of Name of MonthMMMMM
Day as 2D
Day as 02DD
Day as Sun-SatNN or DDD
Day as Sunday to SaturdayNNN or DDDD
Day followed by comma, as in “Sunday,”NNNN
Year as 00-99YY
Year as 1900-2078YYYY
Calendar weekWW
Quarterly as Q1 to Q4Q
Quarterly as 1st quarter to 4th quarterQQ
Era on the Japanese Gengou calendar, single character (possible values are: M, T, S, H)G
Era, abbreviationGG
Era, full nameGGG
Number of the year within an era, without a leading zero for single-digit yearsE
Number of the year within an era, with a leading zero for single-digit yearsEE or R
Era, full name and yearRR or GGGEE

If you change your locale of LibreOffice e.g. German, you need to use a different code as per below.

LocaleYearMonthDayHourDay Of WeekEra
English – en
and all not listed locales
YMDHNG
German – deJ T   
Netherlands – nlJ  U  
French – frA J O 
Italian – itA G OX
Portuguese – ptA   O 
Spanish – esA   O 
Danish – da   T  
Norwegian – no, nb, nn   T  
Swedish – sv   T  
Finnish – fiVKPT  

List of Time format codes

To format time, use below format codes:

FormatFormat Code
Hours as 0-23H
Hours as 00-23HH
Hours as 00 up to more than 23[HH]
Minutes as 0-59M
Minutes as 00-59MM
Minutes as 00 up to more than 59[MM]
Seconds as 0-59S
Seconds as 00-59SS
Seconds as 00 up to more than 59[SS]

Drop a comment, if you have any questions/suggestions.


Looking for something else?

Read our complete tutorial index of Calc, Writer, Impress and Draw.


Join our Telegram channel and stay informed on the move.

Related


arindam

IT professional by profession and founder of libreofficehelp.com. Loving Linux and other technologies since 2002. I believe in open source and its philosophy. Follow me on Twitter or email me.

24 Comments

  1. How can I change the default date or time format in a spreadsheet or even globally in LibreOffice Calc?

  2. you wrote “… day represent a number counted from the date Jan 0, 1900.”

    That’s only correct, if you make a special setting in Tools -> Options -> LibreOffice Calc -> Calculate. The default is to count days since Dec 30, 1899 (which is day 0).

  3. I’m amazed that LibreOffice doesn’t support fractional seconds. Apparently this is too complicated for them.

  4. Probably I’m stupid, but I found all these replies incomprehensible. Here is how to convert a list of dates in the wrong format to the format you want.
    Suppose you have a list of dates in an excel like:-
    2019-10-11
    2021-06-21

    But, you want:
    OCT 2019
    JUN 2021
    TO CONVERT THE CELLS TO YOUR FORMAT , DO THE FOLLOWING:
    1. Copy all your list of dates into a text file and save it using a program like xed.
    2. Cancel all the dates in your excel file
    3. Right click over the column heading where you want to insert the list of dates.
    4. From the dropdown menu select “Format Cells”.
    5. Select the format you want. If the format you want doesn’t exist, you can create it as a user defined format. In my case, I selected Category Date and then Format Dec 1999 and the format code is MMM YYYY.
    Then , click on the OK button.
    6. Now, go back to your list of dates in your text file and select them all and copy them to your clipboard.
    7. Then, click on cell 2 of the column in your excel where you want to put the dates. then EDIT then PASTE THEN ok.
    8. THIS WILL GIVE YOU THE LIST OF DATES IMPORTED INTO YOUR EXCEL FILE IN THE REQUIRED FORMAT.

  5. Can we use PHP date types, such as,
    1st, 2nd, 3rd, 4th, 5th,… 20th, 21st, 22nd, 23rd, 24th, 25th,… 30th, 31st?

    In my region, long dates are written as such,
    Tuesday, 3rd November 2020.

    The best that I can see is
    Tuesday, 3 November, 2020,
    and that is not acceptable.

    • No. Adding ordinals such as 1st – 2nd : not possible at the moment in Calc using custom user-defined formats. This feature not available yet. However, you might write a formula to detect the days and convert them to the desired value. That would be overkill.

  6. How do I format cells to represent running times? For example, if a cell has 13:37, it’s because something happened for 13 hours and 37 minutes, not 1:37pm. Thanks.

    • The problem is you can’t do this using number format. Because 0.5 is a decimal number. It’s like half of 24 hours. But time is represented in a different way as minutes and seconds.

      However, you can achieve what you are asking using the below formula where A1 contains 1.5

      =TRUNC(A1) & ” ” & (A1-TRUNC(A1))*24

  7. I have a list of bank transactions that are due, but how do I omit/change any Saturday or Sunday transactions to the following Monday?

  8. In my bank transactions, I would like any Sat or Sun dates to be moved to the monday. How would I format the column?

    • Use the WEEKDAY function. Weekday function returns number of the day. For example, it returns 7 for Saturday and 1 for Sunday. So, if you have a date in cell B2, you can use a simple IF to convert it to Monday. Use nested if for Sunday logic with 1.

      =IF(WEEKDAY(B2)=7,”Monday”,TEXT(B2,”dddd”))

  9. I would like to know if there’s an easy way to convert dates that have 2021 into 2020. For instance, I am entering receipts from 2020 but the default (since it’s now 2021) is for my 03/25 to convert to 2021-03-25. Instead, I want 2020-03-25. I would love that to convert to 2020-03-25 without my having to write 2020/03/25 each time. Can I do that?

    I thought one way might be to go ahead with them as 2021 and then switch to “General” format and subtract 365, then switch back to “Date.” But that seems clunky. Can’t I just have it autofill a chosen year if I’m entering the month and day?

    • No. Unfortunately, there is no option to turn off the current year as default when entering the date as MM/DD or DD/MM.

      I would suggest you two options.

      a) After you entered, do a FIND-REPLACE ALL by 2020 replacing all 2021.
      b) change the year of the computer date where you are working. This might have other problems as well.

  10. If I have a cell containing a date, formated to the eye as YMD, and I want to use this formatted string in a formula, instead of its native value, how would I do that?

    • No. You can not do that. The visual representation will not work in the formula. So, you should use TEXT function to convert the date to the actual value. For example –

      if your date is 04/12/2021 (April 12) in cell B3 – then formatting it as YYMD would give you 21412.

      To get that value, use

      =TEXT(B3,"yy") & TEXT(B3,"m") & TEXT(B3,"dd")

      which also give you 21412. Then apply formula there.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.