Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the difference between login time and current time. 1

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
I am storing the login time in a cookie... for the time being. I would like to have one of my pages show the difference in minutes between the login time, and the current time. Such as, you have been logged in for x minutes. How can I?
 
Well as you said put the time into the cookie. On the page your displaying time elapsed use the datediff function That'l do donkey, that'l do
[bravo] Mark
 
Can't find any info on DateDiff? Trying this:
Code:
DateDiff(Request.Cookies("time").Value, DateTime.Now())
 
Qwert I dont remember if you have VS or not but even if you don't the documentation is all on the MS site.

The format is as follows
DateDiff(DateInterval.Day, date1, date2)

The value of date1 is subtracted from the value of date2 to produce the difference.

The DateInterval can also be as .hour, .minute, .second That'l do donkey, that'l do
[bravo] Mark
 
I do, but don't really use it... not for this...
Here is what I ended up with, and it works:
Code:
Sub Page_Load(Source As Object, E as EventArgs)
 timeOn.text = Request.Cookies("time").Value
 timeNow.text = Now()
 timeLeft.text = DateDiff("n", Request.Cookies("time").Value, DateTime.Now())
End Sub

Here is where I finally found the info. Class Browser doesn't show it. That's where I had been looking.

 
Fortunately that worked for you. You actually looked up a VBA function not VB.NET

The VB.net datediff function does allow you to use that syntax. Likely to allow for backward compatability as it doesn't follow an object oriented methodology.

Glad it worked though. That'l do donkey, that'l do
[bravo] Mark
 
True true... actually, it looks like DateTime has a Public operator to do this now:

Very interesting... You just need to know where to look. DateTime is a System object... and not buried to deep inside anything else... I hope I'm not just loading up the server with this post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top