473,626 Members | 3,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Property Feature For Comparing DateTime

Hi,

I dont know whether I am doing this correctly or not. I want some procedure
to fire when the time b/w the last and the current request is > 15 min
I declared a global variable (txtPrev as string) and set it initially to
datetime.now (tostring) and the clicked event of a button compare that
datetime.now - prevtime.. but the global variable has nothing in it... why?
I thought it would be set when declared globally for some reason its null
(either my understanding is totally wrong or something is screwed up

If newDateTime.Now .Subtract(DateT ime.Parse(txtPr ev)).TotalMinut es > 2 Then
<-- error out here

else

end if

I TRY THIS TOO... BUT DOES NOT WORK EITHER

I have no understanding of Property but thought I would try... please do
help me in understanding this
Public Property X() As DateTime
Get
Return X

End Get

Set(ByVal Value As DateTime)
X = Value

End Set

End Property

Suppose during page load I do this t_PrevTime = X.Now

and then while comparing at the clicked_event why does it take the value of
#12.00 AM#
If prevDateTime.No w.Subtract(X).T otalMinutes > 2 Then <--- thought it
should set X to X.Now

else

Endif
Please advice... I feel as if I am doing this in worst possible way, if
there is a better way please do let me know.
Thanks in Advance,
Stephen
Dec 15 '05 #1
2 1152
here's an idea

in your Page_Load method, cache some object with a sliding expiration
of 15 minutes.

then, on subsequent loads of the page, simply access that cache item to
keep it "fresh"

so, something like this (i have not tested this code - caveat emptor):

protected void Page_Load(objec t sender, EventArgs e)
{
System.Web.Cach ing.CacheItemRe movedCallback onRemoveCallbac k =
new
System.Web.Cach ing.CacheItemRe movedCallback(m yCallbackHandle r);

if (!IsPostBack)
{
Cache.Add("x", "x", null, DateTime.MaxVal ue,
new TimeSpan(0, 15, 0),
System.Web.Cach ing.CacheItemPr iority.Normal,
onRemoveCallbac k);
}
else
{
// just access the cached item to keep it "alive" in the
cache, and
// therefore not provoke the firing of the onRemoveCallbac k
string y = (string)Cache["x"];
}

}

public void myCallbackHandl er(String k, Object v,
CacheItemRemove dReason r)
{
// do your processing here for the case
// where the page has not been accessed for the last 15 mins
}

Dec 15 '05 #2
Thanks Albert,
will work with the suggestion
Thanks,
stephen

"albert braun" <bc************ ***********@yah oo.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
here's an idea

in your Page_Load method, cache some object with a sliding expiration
of 15 minutes.

then, on subsequent loads of the page, simply access that cache item to
keep it "fresh"

so, something like this (i have not tested this code - caveat emptor):

protected void Page_Load(objec t sender, EventArgs e)
{
System.Web.Cach ing.CacheItemRe movedCallback onRemoveCallbac k =
new
System.Web.Cach ing.CacheItemRe movedCallback(m yCallbackHandle r);

if (!IsPostBack)
{
Cache.Add("x", "x", null, DateTime.MaxVal ue,
new TimeSpan(0, 15, 0),
System.Web.Cach ing.CacheItemPr iority.Normal,
onRemoveCallbac k);
}
else
{
// just access the cached item to keep it "alive" in the
cache, and
// therefore not provoke the firing of the onRemoveCallbac k
string y = (string)Cache["x"];
}

}

public void myCallbackHandl er(String k, Object v,
CacheItemRemove dReason r)
{
// do your processing here for the case
// where the page has not been accessed for the last 15 mins
}

Dec 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
13115
by: Donnal Walter | last post by:
I was very surprised to discover that >>> import datetime >>> x = datetime.date(2004, 9, 14) >>> y = datetime.datetime(2004, 9, 14, 6, 43, 15) >>> print x == y True How can these two objects be considered equal? Is there a *general* way to test for date != datetime as well as 4.5 != 4.6?
3
2511
by: STech | last post by:
What is the recommended way for comparing two nullabe DateTime types using the CompareTo method. DateTime? d1 DateTime? d2 return d1.Value.CompareTo(d2.Value) //This obvoiusly will fail if one is null return d1.GetDefaultOrValue().CompareTo(d2.GetDefaultOrValue()) //this works but it is a hack as you are converting a null type to DateTime.MinValue and
2
1823
by: Duppypog | last post by:
I'm trying to compare a date stored in a database with today's date using an If statement, but it's not returning true. Example, value in database is 11/5/2003 with today being 11/6/2003. Can someone spot the problem? Thanks, Lynnette Here's the code: sSQL = "Select PWExpire FROM tblUsers where strUserName = '" & stUser & "' AND strPassword = '" & hshPW & "'"
2
1583
by: Philip Townsend | last post by:
I am having difficulty with a simple routine as follows: public static bool VerifyExpirationDate(DateTime date) { if(date>=DateTime.Now)return true; else return false; } The problem is that when today's date is passed in, the method returns false. Any ideas? Thanks!
2
3331
by: Manny Chohan | last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30 AM. How can i compare dates .net c# or if there is any other way such as Javascript. Thanks Manny
4
7328
by: Mika M | last post by:
I need to compare two DateTime variables named as t1 and t2 using VB.NET 2003. If t1 is any earlier time as t2, only then program should do something like... If (t1 < t2) Then 'DoSomethingHere... End If But I don't figue out how comparing DateTimes is working.
5
5653
by: JL | last post by:
I need to compare two times. The problem I have is this: In my code I create a time variable using the format statement below: dim firstTime as DateTime fistTime = Format("12:00:00 AM", "T") I then store this in an Access database DateTime field. When I read it back from the DatTime field. The values do not compare.
2
4233
by: Benton | last post by:
Hi there, I'm creating a custom server control, inheriting from TextBox. It has this AsDateTime property that returns the textbox contents converted to the nullable DateTime data type, as follows: public class TextBoxWeb : System.Web.UI.WebControls.TextBox {
3
2702
by: Anil Gupte | last post by:
I am using the followig code: SqlConnection con = new SqlConnection(strcon); con.Open(); string strSelect = "Select PaidUntil from Users where username='" + un + "'"; SqlCommand cmd = new SqlCommand(strSelect, con); SqlDataReader dr; dr = cmd.ExecuteReader(); dr.Read();
0
8202
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8641
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5575
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.