How do I format a datetime on sqlite with timezone? - xcode

for example I have this date jan 5, 2010 14:00 wednesday gmt-8
how do I implement this so I can save it with timezone?,
I can save this using nsformatter with yyyy-MM-dd hh:mm
and saves as
2010-01-05 14:00
but how about w/ timezone?
(it should be saved in datetime format.. not text format)

You can use [format setDateFormat:#"yyyy-MM-dd hh:mm a"] for timezone it will give output like this "2010-01-05 02:00 PM"
or
[format setDateFormat:#"MMM dd, yyyy hh:mm a"]

Put the timezone in another column and you won't break the limited existing date functionality of SQLLITE. Its really easy to add columns to sqllite with an alter table statement. Android SQLite Database, WHY drop table and recreate on upgrade
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.

Related

Easiest way to access .NET TimezoneInfo from Asp classic page [duplicate]

I'm trying to change some old .asp files with vbs. Our database is going to be converted to store dates in UTC, but on webpages it should show dates and time in "Europe/Helsinki" timezone(
TimeZoneInfo.FindSystemTimeZoneById("FLE Standard Time")
in c#). How can I cast the UTC date I get from db query( the query is run in the .asp file as well and the result put into table) to correct date time using vbscript?
Just offset the UTC dates using DateAdd().
Const EETOffset = -2 'EET offset from UTC is -2 hours
Dim dbDateValue 'Assumed value from DB
Dim newDate
'... DB process to populate dbDateValue
newDate = DateAdd("h", EETOffset, dbDateValue)
Note: One problem with this approach is you will also have to compensate for EET and EEST (Eastern European Summer Time) manually based on the time of year. Which is also more difficult when you take into consideration some places don't use it and use EET all year round instead.
See EET – Eastern European Time (Standard Time).
Depending on the RDMS you are using you should even be able to manipulate the dates before they get to the page as part of the initial query.
Useful Links
Format current date and time
How to format a datetime with minimal separators and timezone in VBScript?

Pentaho kettle value conversion

I wanted to convert microseconds to data:
60000000 -> 1997-2-12 (something like this).
This means the new field contains year-month-day-hour-minute-seconds-microseconds
Thx.
microseconds (or any time span) can't be directly converted to a date, because you need a starting date and then add your timespan to that date, to end up with a calculated date. Quite often, timespans expressing dates are using the unix epoch start date of January 1st, 1970, 0:00 UTC as their base date.
To calculate your target date, you could use the Calculator step from Kettle. First reverse the sign of your microseconds timespan (multiply with -1), then use the calculation Date A - Date B (milliseconds) to calculate your new date.
as your new field is a Date field, you can format the output to your own specification.

In NetSuite Advanced PDF Template, I got 00/01/2017, 0th moth, when I set date format to mm/dd/yyyy

I used <#setting date_format="mm/dd/yyyy"/> to set my date format. However, When I print the dates, it always print 00/xx/xxxx, 0th month.
mm means minutes, not months in year; use MM for that: MM/dd/yyyy. See: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Dealing with timezones in vbscript

I'm trying to change some old .asp files with vbs. Our database is going to be converted to store dates in UTC, but on webpages it should show dates and time in "Europe/Helsinki" timezone(
TimeZoneInfo.FindSystemTimeZoneById("FLE Standard Time")
in c#). How can I cast the UTC date I get from db query( the query is run in the .asp file as well and the result put into table) to correct date time using vbscript?
Just offset the UTC dates using DateAdd().
Const EETOffset = -2 'EET offset from UTC is -2 hours
Dim dbDateValue 'Assumed value from DB
Dim newDate
'... DB process to populate dbDateValue
newDate = DateAdd("h", EETOffset, dbDateValue)
Note: One problem with this approach is you will also have to compensate for EET and EEST (Eastern European Summer Time) manually based on the time of year. Which is also more difficult when you take into consideration some places don't use it and use EET all year round instead.
See EET – Eastern European Time (Standard Time).
Depending on the RDMS you are using you should even be able to manipulate the dates before they get to the page as part of the initial query.
Useful Links
Format current date and time
How to format a datetime with minimal separators and timezone in VBScript?

Convert Unix Timestamp - Spotfire Analyst

I'm importing SQL data into Spotfire Analyst. All of the date and time fields are in the form of a Unix timestamp. What's the best way to convert this into an actual date format that I can manipulate in Spotfire?
Utilizing a calculated column you can calculate the datetime based on the UNIX epoch.
We simply add our seconds to the DateTime of the UNIX epoch (JAN 01 1970 00:00:00 UTC) to get the result. Below is an example of the UNIX time when I started writing this post.
DateAdd("second",1429733486,DateTime(1970,1,1,0,0,0,0))
The below is what should work for you:
DateAdd("second",[UNIX_TIMESTAMP_COLUMN],DateTime(1970,1,1,0,0,0,0))
Keep in mind these dates produced will be in the UTC timezone as per the JAN 1 1970 epoch. If you need them in your local time zone you may have to adjust accordingly with further DateAdd functions adding/subtracting time as per current conversions. Also, if you observe daylight savings time you may need to add some extra case logic to handle that as well.
Please let me know if you have any questions or need further clarification.
In 7.0 and later you can use
FromEpohTimeSeconds([UNIXDATE])
or
FromEpohTimeMilliseconds([UNIXDATE])

Resources