?
Solved

C# convert LastLogon value to Days

Posted on 2011-04-22
7
Medium Priority
?
773 Views
Last Modified: 2012-05-11
Experts:

This issue has been bothering me for quite some time....

I've got a program I'm designing to assist with local profile removal.  I've got the actual removal of the profile processing correctly, but I'm having problems getting the calculation of the last logon time for the particular profile.

I found the Win32_NetworkLoginProfile class and a LastLogon value that gives the number of seconds past 00:00:00 January 1, 1970 and I need help converting that to a date so I can then find out how long since that last logon occurred.

Any suggestions?
0
Comment
Question by:piattnd
  • 4
  • 3
7 Comments
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35450664
Hi, use the TimeSpan.FromSeconds() method
0
 
LVL 12

Author Comment

by:piattnd
ID: 35450746
TimeSpan.FromSeconds(#of seconds returned)?
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35450752
Yes, but I will give you a better code... a moment...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35450773
Clear? :)
string myStringDate = "00:01:15 January 1, 1970";
DateTime myDate = DateTime.Parse(myStringDate);
TimeSpan duration = myDate.Subtract(new DateTime(1970, 1, 1));
Console.WriteLine(duration.TotalSeconds);
Console.WriteLine(duration.TotalMinutes);
Console.WriteLine(duration.TotalHours);
Console.WriteLine(duration.TotalDays);
Console.WriteLine(duration.Days);

Open in new window

0
 
LVL 12

Author Comment

by:piattnd
ID: 35469152
Let me take a look and see if I can figure it out.  I need to look at the value that gets returned from me to let you know what data I have to work with.
0
 
LVL 17

Accepted Solution

by:
Carlos Villegas earned 2000 total points
ID: 35469172
Good let me know
0
 
LVL 12

Author Closing Comment

by:piattnd
ID: 35797006
Sorry it took me so long to accept the answer.  Been a crazy few weeks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question