[Solved] Timestampdate to string or number

Creating tables and queries
Post Reply
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

[Solved] Timestampdate to string or number

Post by gkick »

Hi All,

How can I convert the year contained in a timestamp to a string in order to update another field? Have experimented with the convert and substring function but to no avail

Thks
Last edited by gkick on Sat Dec 28, 2019 2:22 pm, edited 2 times in total.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
User avatar
Sliderule
Volunteer
Posts: 1279
Joined: Thu Nov 29, 2007 9:46 am

Re: Timestampdate to string or number

Post by Sliderule »

Use the built-in function TO_CHAR or YEAR.

For Example Run the following Query:

Code: Select all

Select DISTINCT 
   CURRENT_TIMESTAMP as "CUR_TS",
   YEAR(CURRENT_TIMESTAMP) as "INT_YEAR ",  -- Returns an integer range 1-9999
   TO_CHAR(CURRENT_TIMESTAMP,'YYYY') as "TO_CHAR",  -- Returns text string
   TO_CHAR( {TS '2027-12-28 15:30:27'},'YYYY') as "TO_CHAR_2027" -- Returns text string
From INFORMATION_SCHEMA.SYSTEM_TABLES
I hope this helps, please be sure to let me / us know.

Sliderule

Thanks to add [Solved] in your 1st post Subject (edit button top right) if this issue has been resolved.
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: Timestampdate to string or number

Post by gkick »

Beautiful, thank you Sliderule :D

GK
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
Post Reply