How to change SQLite time format datetime - iphone

I am trying to get the date from SQLite. I am getting timestamp in coredata, but I need to see the date. What is the command to get the timestamp converted into YYYY-MM-DD format? My query is:
SELECT ZDATE FROM ZWEATHER
Zdate is datetime.

You may be looking for the DATE() function, as seen in the SQLite manual:
SELECT date(ZDATE);

The first thing to understand is that SQLite has no date type. It has no time type either.
It only offers some time functions. The page Piskvor links to is what you need. You enter the date and/or time in your database as a string following one of a few formats available:
YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
YYYY-MM-DDTHH:MM
YYYY-MM-DDTHH:MM:SS
YYYY-MM-DDTHH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
Or as a floating point value representing the Julian day number.

Related

Where should I format date from a database before displaying it - Android

I store the date in an SQLlite database as a long and want to view it in a ListView. At the moment I have the Database, a content provider, a loadermanager and a custom adapter. At the moment I'm using the custom adapter to format the data. However, there may be other possibilites, so I'm interested what is best practice.
An alternative, assuming that saving it as a long meets the recognised time string formats as per :-
Time Strings A time string can be in any of the following formats (e.g. the very last one):
YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
YYYY-MM-DDTHH:MM
YYYY-MM-DDTHH:MM:SS
YYYY-MM-DDTHH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
now
DDDDDDDDDD
SQL As Understood By SQLite - Date And Time Functions
would be to extract the data in the required display format.
For example consider the following :-
DROP TABLE IF EXISTS mydata;
CREATE TABLE IF NOT EXISTS mydata (mydatetime INTEGER);
INSERT INTO mydata VALUES(1092941466); -- <<<<<<<<<< 2004-08-19 18:51:06
SELECT *, datetime(mydatetime,'unixepoch'), strftime('%d/%m/%Y %H:%M:%S week %W of Year %Y',mydatetime,'unixepoch') FROM mydata;
The result would be :-
Reading the link above should indicate the flexibility of this approach.

Date stored in different format

I have this date "2018-05-30T16:19:58.016Z" coming from my Angular app.
In Spring, the field date is as follows :
#JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
private Date date;
The date is well stored, but with this format YYYY-MM-dd.
Is there anything that I'm missing ?
MySql date type can't hold data with timestamp. It has to be datetime in order to contain date time with timestamp data.
You probably have to specify the date format going out to the storage, as #JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") only specifies the date format for parsing the date into the Date object. Even if your Date has all of the seconds and timezone information, the default Date toString() is still
Formats a date in the date escape format yyyy-mm-dd.
according to the Java 8 docs. So if you are using that, it would most likely drop all that extra information on conversion.
You can look at this Convert java.util.Date to String for information on how to get a Date to a formatted String.

Converting Date Column Format to Hours in Talend Open Studio

I am interested in converting a date column with a string mm/dd/yyyy hh:mm:ss to an hour format using Talend Open Studio. I want the hour of the day from the Date column.
If the String has already been converted to a Date, you could retrieve the hour of the day with formatting in tMap:
TalendDate.formatDate("HH",myDate)
This will return a String with the hour of the day.
If the String has not been converted, I suggest converting it before - it is always better to have a Date and work on the Date type than doing String processing.

Datatype to store date of format yyyy-mm-dd hh:mm:ss in postgresql

I am not knowing which datatype to be assigned to the data of format yyyy-mm-dd hh:mm:ss?
I use postgresql database.
You're looking for timestamp (with or without timezone, with timezone preferred to store the actual data)
See PostgreSQL's documentation on Date/Time Types

Saving Timestamp into sqlite

18.11.2009 10:32:00
I want the value in between the above tag(created) to be inserted into the sqlite db for which i have taken a column of type timestamp....
how can i store this value in that column??
please advise...
Well, it depends in which format you want to save it in your database.
If you want to save it in the string form, then save it directly by making an object. But, use the datatype of string type.
Another option is to save it using the date datatype, seeing as sqlite doesn't have a dedicated date/time datatype.
Use a formatter to set the date format:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"dd-MM-YYYY HH:MM:SS"];
Then make Date object, and save it.
You should replace dots by hyphens and place months, days and year parts in correct order.
According to sqlite docs these are the date and time accepted formats:
YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
YYYY-MM-DDTHH:MM
YYYY-MM-DDTHH:MM:SS
YYYY-MM-DDTHH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
now
DDDDDDDDDD
Two options here (if you want sorting, which I assume you do):
Add as a string, but re-order the fields from highest to lowest. After that, it's a simple matter to sort via text. This is the slower option.
2009.11.18 10:32:00
Convert to a UNIX timestamp, I.E. seconds since Jan 1st, 1970. This is the fastest option.
1261153920
It is then simple to pull it out using date and time functions.
Note that SQLite does not have a date/time data type.
Make object for date
then use this
[date timeIntervalSinceDate:objDate];
this give time interval beetween the date and objDate. two dates(date and objDate) for finding timeInterval.
Save this by convert it into string.