OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[SOLVED] How to convert a timestamp field to a date field

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
darkshark
General User
General User


Joined: 08 Feb 2010
Posts: 32

PostPosted: Sun Apr 04, 2010 9:05 am    Post subject: [SOLVED] How to convert a timestamp field to a date field Reply with quote

Hi,
i'm wondering if is it possible to convert a timestamp field to a date field (like DD/MM/YY)...

I know that i can "convert" a timestamp to a date with the to_char command, but in this case i lose the possibility to relate my date to a real date filed.

I wonder even if there's a way to group a timestamp filed in order to have a row for each day, i know that i can group using to_char, but even in this case the date that i get is a string and not a real date.

Thanks in advance.


Last edited by darkshark on Sun Apr 04, 2010 10:07 am; edited 1 time in total
Back to top
View user's profile Send private message
Sliderule
Super User
Super User


Joined: 29 May 2004
Posts: 2477
Location: 3rd Rock From The Sun

PostPosted: Sun Apr 04, 2010 9:43 am    Post subject: Reply with quote

darkshark:

You asked:
darkshark wrote:
i'm wondering if is it possible to convert a timestamp field to a date field (like DD/MM/YY)


Yes . . . by using the CAST function.

I am making several assumptions, based on your post . . . and . . . for others reading this.
  1. You are using HSQL as your database engine ( you can confirm this by looking at the status line ( at the bottom ) after opening your OpenOffice Base file ).

  2. You do NOT want to 'permanently' change your table definition, but rather, just for a Query. Smile

While creating your Query . . . if we assume a Table Name of "MyTable" and a Field Name of "MyTimeStampField" . . . use, on the Field line . . .

Code:
CAST( "MyTable"."MyTimeStampField" as "DATE")

the above will return a value for a field with a database definition of DATE from the TIMESTAMP portion . . . and you could assign an Alias Name if you so desire.

Therefore, to return just this 'portion' ( date ) of the field, you could enter:

Code:
GROUP BY CAST( "MyTable"."MyTimeStampField" as "DATE" )

NOTE: You MAY have to 'format' the resulting date field as you want it - after running the Query - ( DD/MM/YY ) by selecting the Column and Format -> Date -> Select your desired date format.

I hope this helps, please be sure to let me / us know. Smile

Sliderule

Thanks to add [Solved] in your first post title ( edit button ) if your issue has been fixed / resolved.
Back to top
View user's profile Send private message
darkshark
General User
General User


Joined: 08 Feb 2010
Posts: 32

PostPosted: Sun Apr 04, 2010 10:09 am    Post subject: Reply with quote

It works perfectly.
Thank you for your precious advice. :D
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group