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

This widget could not be displayed.
Hi Adam,

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

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:

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.


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.

This widget could not be displayed.

Hi Adam

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


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.

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

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


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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

199 views 1 3
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