GParekar
GParekar

Reputation: 1219

How to merge two separate column data into one column in sqlite android

I store hour and minute in two separate column. i want to combine it like as hour:minute(9:15) and store timeunit(AM-PM) in separate column.how to do this can any one knows.hour and minute of String type.

Upvotes: 0

Views: 84

Answers (2)

Ivan Dokov
Ivan Dokov

Reputation: 111

Try to store the time in one column use one of the following types.

SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

  • TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
  • REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
  • INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC. Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.

Its easier to store the time in one INTEGER column in milliseconds. And recreate it by Date date = new Date(milliseconds). Then to get the hours and minutes from date.

Upvotes: 2

Abhishek Patel
Abhishek Patel

Reputation: 4328

Try something like this

SELECT (column1 || ":" || column2) AS expr1 FROM your_table;

Upvotes: 1

Related Questions