Convert Unix Timestamp - Spotfire Analyst - tibco

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])

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?

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?

Unix Shell Script Time Zone BST Or GMT

This is what i'm trying to do:
I want to create a simple shell script that checks the current timezone in the UK.
i.e. BST or GMT.
I only can display the time for the current timezone the UK is in. i.e. UK is in GMT right now and I can only display that time. [TZ=GMT date]
Please note: I do not wish to permanently modify the UNIX time zone on the server (currently CET)
Based on that I need to do some calculations (which I'm fine with)
I have already searched and I cannot find anything specific to this problem. Thank you for your help
To get the date for a particular timezone, you can do:
TZ=GMT date
(Or date +%s if you want epoch format, which is also TZ independent, but altogether friendlier for calculations. ).
For what it is now, relative time I think it's as simple as:
TZ=Europe/London date
Which I think should cause your system to report BST/GMT appropriately.
If you want it to specifically report the offset, you can use the %z format specifier:
TZ=Europe/London date +"%Y%m%d %H:%M:%S %z"

Should I store the local time for events instead of UTC?

I am currently storing events of some entities in UTC time but I am not sure if I should do that in this case. Imagine there's an event at 10pm local time (-4h UTC) and a mobile App fetches "todays events". This could e.g. look like this:
App sends request to fetch all clubs in the near location
After receiving all clubs it sends a request to get all events for today. It therefore sends the local time Sun. 10pm to the server.
The server would convert the local time of the mobile device to UTC Mon. 1am and fetch all events from Monday. But of course that was not what I wanted.
Fetching all events from the clubs and convert them to their local time using their local time offset information is not really a great solution.
So wouldn't it be better to just store all events in local time? In that case the mobile App would send its local time to the server which would be able to query all events from the clubs in local time as well.
This sounds much simpler to me but I am not sure if I overlook something.
So what would I do in this case?
Yes, storing everything in UTC is probably the best solution.
You don't say how you are "storing" the dates/times, but if you are using Dates or Joda equivalents, then you should know that their underlying representation is effectively in UTC (they represent a moment in time as an offset in milliseconds since the "Epoch", which is Midnight, Jan 1, 1970 UTC). These dates only have a timezone when you format them as Strings.
Most databases do something similar (store the date in a common timezone, usually UTC). The major exception that I've found is the generally available date-time related column types in MS SqlServer which by default store everything in the local timezone of the server.
Also be aware that if you use SQLite, and you store a date/time by passing a String in SQL that contains a timezone, SQLite will store it without warning, but will ignore the timezone and assume that the timezone is UTC, giving you a result other than what you might expect.
For more on this, see my (old) blog post at http://greybeardedgeek.net/2012/11/24/java-dates/
The other answer is correct. Some more thoughts here.
A time zone is more than the offset from UTC mentioned in the Question. A time zone is also the set of past, present, and future rules for anomalies such as Daylight Saving Time. You should refer to a time zone by its proper name, continent plus Slash plus city or region. Never use the 3-4 letter codes such as EST or IST.
To search for events in the user's "today", you must know the user’s time zone. For example, a new day dawns earlier in Paris than in Montréal. After the stroke of midnight in Paris we still have a few hours of “yesterday” left to go in Montréal.
While you can make a guess as to the user’s time zone, the most reliable way is to ask the user.
DateTimeZone zone = DateTimeZone.forID( "America/Montreal" );
DateTimeZone now = DateTimeZone.now( zone );
DateTime today = now.withTimeAtStartOfDay();
DateTime tomorrow = today.plusDays( 1 );
// Search for events that start >= today AND that start < tomorrow.
To search Joda-Time objects, use the Comparator built into DateTime. That comparator works across objects of various time zones.
To query a database, convert that pair of DateTime objects into java.sql.Timestamp objects. You do that by extracting and passing the count of milliseconds since the epoch of 1970 in UTC.
long m = today.getMillis();
java.sql.Timestamp tsToday = new java.sql.Timestamp( m );

How do I format a datetime on sqlite with timezone?

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.

Resources