How do I convert Last Login in DB (MSSQL) to date/time?

I am trying to create a SQL query or modify the data in Excel after export from SQL which will give me the correct Date/Time for Last Login of users in the system. However, the Sample SQL queries reference a to_timestamp function which is an Oracle only function, and i haven't been able to figure out what date is the reference date for the Milliseconds or how to convert the milliseconds correctly to be added to that date.

I even reached back to Algrebra class knowledge, and created 2 equations with 2 variables in order to solve for them and calculate based on that, but values outside of my reference times are still inaccurate. Any help will be appreciated. Thanks.

DB: MSSQL 2008

5 answers

1 accepted

Hi Adam,

For MYSQL server, you may use the FROM_UNIXTIME function. Here is an example:

SELECT
theTimeStamp, FROM_UNIXTIME(theTimeStamp)AS readableDate FROM theTable WHERE theTable.theField = theValue;

About SQL server, I'm not quite sure, but you may try do that using a query lin the following:

SELECT
CONVERT(TIME, DATEADD(ms, SUM(duration/10000%1000), DATEADD(ss, SUM(duration/10000000),0)))FROM tblMediaFileProperties

In case of any problem, try to use a clone database in MYSQL server to double check it.

Cheers,

Paulo Renato

From my original question, i specified at the end that we are using MSSQL 2008, therefore, functions for MYSQL do not work. I also don't think it would be very useful to temporarily copy my database to a MYSQL database just to run the query once because I am planning on running this on a regular basis.

I apparently didn't read your whole post with the CONVERT part. I did have to modify the statement a little bit, but here is what i came up with which works.

CONVERT(DateTIME, DATEADD(ss, CAST(lastLoginMillis as Numeric(30))/1000, DATEADD(hh, -6,'1970-01-01'))) as LastLogin

Then i was able to get the correct date/time. I think the main thing that messed me up is that in the SQL examples that Atlassian provides, they reference the incorrect attribute to get the last login. They reference the PreviousLogin attribute which is why my dates were so wonky when comparing them to the values from within the administrator interface.

Hi Adam

I believe that you may try to create a new SQL query using the following link as an example:

https://confluence.atlassian.com/display/JIRACOM/Example+SQL+queries+for+JIRA#ExampleSQLqueriesforJIRA-Listusername,fullname,emailaddress,logincount,andlasttimeloggedin

Cheers,

Paulo Renato

That is what i meant with my original question when i mentioned "the Sample SQL queries reference a to_timestamp function which is an Oracle only function". That is obviously where i got the basics of my query and how to get the value for Milliseconds out of the database.

However, my question is regarding how to convert that Last Login (in Milliseconds) into a readable date/time? As i tried to explain in my original question is that i have tried the basics on how to convert this value to a valid date, but have not found anything that converts the values correctly for all users.

Does anyone else have any suggestions? Please help. Thanks.

0 votes
Renjith Pillai Community Champion Jan 04, 2013

Can you tell the type of the column in the MS SQL database? And give a sample of the value from database?

The column type in the database is nvarchar(255) and an example of a value is:

1366052401471

Which should equate to 2013-04-15 13:58:xx:xxx in the CDT timezone.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,968 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot