3

How can I get rid of the time zone in the date/time field?

So I have a GeoPackage with the following data:

enter image description here

and want to get just 2021-06-07 16:25:40

Taras
  • 32,823
  • 4
  • 66
  • 137

3 Answers3

3

In my QGIS (3.22), when I use datetime format, I get timezone information included by default. You can convert it to a string to get rid of it - use this expression, where datetime is the name of the field containing the datetime-information:

left(to_string(datetime), 19)

However, you can't use the resulting string field as a datetime field any more. Including timezone makes sense - as 2021-12-06 14:48:41 is not the same everywhere on Earth.

Taras
  • 32,823
  • 4
  • 66
  • 137
Babel
  • 71,072
  • 14
  • 78
  • 208
  • thank you! so there is an issue with the version? – kartographinya Dec 06 '21 at 13:49
  • No, I think including timezone is intended, that's not an issue. This format is not primarily intended for visualization - if you want to visualize, best convert to a string. – Babel Dec 06 '21 at 14:06
3

After inspecting provided GeoPackage I could not find the problem in any of your datetime fields, specifically "Save_times1" and "Loc1".

fields

attribute_table


Proceed with RMC > Properties > Attributes Forms > Fields (see documentation) where change the Field Format from ISO Date Time into Date Time.

window

Before:
attribute_table1

After:
attribute_table2

Taras
  • 32,823
  • 4
  • 66
  • 137
  • it's already date time, I've checked. I will share my data in a second. – kartographinya Dec 06 '21 at 14:20
  • @Taras: I downloaded the Geopacke provided by kartographinya and indeed, I get the same format, including timezone: https://i.stack.imgur.com/D4lOM.png This, however, is a visualization issue and I guess it has to do with system settings - QGIS just takes the options used by the operation system. As you see in my screenshot, if you try to edit a field, the timezone disappers. – Babel Dec 06 '21 at 14:56
  • So the question is why the timezone bothers you? In case you use several timezones, it matters, of course. If that is the case, I think you should reformulate the question or ask a new one. If you just want to use the time as a text somewhere, without the disturbing timeone text, converting the field to a string as proposed in my answer should work. – Babel Dec 06 '21 at 14:57
  • @Taras which version of QGIS do you use? – kartographinya Dec 07 '21 at 07:20
  • QGIS 3.18. and you? – Taras Dec 07 '21 at 07:20
  • @Taras 3.22. Ok, it seems that it is just a visualization of a system. – kartographinya Dec 07 '21 at 07:26
  • Yeap. I do think so – Taras Dec 07 '21 at 07:30
2

You need to go to the field calculator. Then tick update existing field. Select your desired field and type:

regexp_replace( "date" , '(MSK)', '')

Then hit OK. Good Luck.

Ash
  • 1,210
  • 7
  • 22