473,808 Members | 2,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dates are Evil! HELP!

I have an event listing on my website that is pulling from SQL.
Unfortunately, the listing is displaying all events, especially those
that are even 2 years old. I want to get rid of them and only display
events that are today or in the future. I need help!

Dim tmpEvents As Events
tmpEvents = New EventsMapper(). GetEvents()
Dim tmpEvent As New [Event]
Dim tmpEventListing As String
For Each tmpEvent In tmpEvents
tmpEventListing += "<font style='font-family: Verdana;
font-size: 10px;'>" & tmpEvent.StartD ate & "</font>" & " <br> " &
"<font style='font-family: Verdana; font-weight: bold; font-size:
10px;'>" & "<A href=javascript :openpopup3(" & tmpEvent.ID.ToS tring &
")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>"

If tmpEvent.StartD ate <= Date.Now.ToShor tDateString
Then
Label2.Text = tmpEventListing
Else
Label2.Enabled = False
End If
Next

This displays all the events, but does nothing for events in the past.
Can you help?

Mar 3 '06 #1
9 1332
Jon
Wouldn't it be easier to simply change your sql to pull events with
"eventdate >= GETDATE()"
<la*****@gmail. com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
I have an event listing on my website that is pulling from SQL.
Unfortunately, the listing is displaying all events, especially those
that are even 2 years old. I want to get rid of them and only display
events that are today or in the future. I need help!

Dim tmpEvents As Events
tmpEvents = New EventsMapper(). GetEvents()
Dim tmpEvent As New [Event]
Dim tmpEventListing As String
For Each tmpEvent In tmpEvents
tmpEventListing += "<font style='font-family: Verdana;
font-size: 10px;'>" & tmpEvent.StartD ate & "</font>" & " <br> " &
"<font style='font-family: Verdana; font-weight: bold; font-size:
10px;'>" & "<A href=javascript :openpopup3(" & tmpEvent.ID.ToS tring &
")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>"

If tmpEvent.StartD ate <= Date.Now.ToShor tDateString
Then
Label2.Text = tmpEventListing
Else
Label2.Enabled = False
End If
Next

This displays all the events, but does nothing for events in the past.
Can you help?

Mar 3 '06 #2
You'd think so, but no...because the same view is used to display
events on another table in the site that is accessed by users that
actually need to see past events to schedule future events.

I just figured it would be easy to put a "if the event date is equal to
or less than today, display it" addition to my code. Unfortunately
now, for some reason it does not seem that easy. Unless I am missing
something obvious?

Mar 3 '06 #3
Make sure you are actually working on "real" dates. Here you are comparing a
date (or perhaps text ?) with text.

For example here in France the 13 of January we'll have :

13/01/2006 < 20/01/1980 as text but of course 20/01/1980 < 13/01/2006 as a
date...
--
Patrice

<la*****@gmail. com> a écrit dans le message de
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
I have an event listing on my website that is pulling from SQL.
Unfortunately, the listing is displaying all events, especially those
that are even 2 years old. I want to get rid of them and only display
events that are today or in the future. I need help!

Dim tmpEvents As Events
tmpEvents = New EventsMapper(). GetEvents()
Dim tmpEvent As New [Event]
Dim tmpEventListing As String
For Each tmpEvent In tmpEvents
tmpEventListing += "<font style='font-family: Verdana;
font-size: 10px;'>" & tmpEvent.StartD ate & "</font>" & " <br> " &
"<font style='font-family: Verdana; font-weight: bold; font-size:
10px;'>" & "<A href=javascript :openpopup3(" & tmpEvent.ID.ToS tring &
")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>"

If tmpEvent.StartD ate <= Date.Now.ToShor tDateString
Then
Label2.Text = tmpEventListing
Else
Label2.Enabled = False
End If
Next

This displays all the events, but does nothing for events in the past.
Can you help?

Mar 3 '06 #4
The dates being posted in the database are being entered as 1/1/1900
and i know Date.Now.ToShor tDateString gives a day that says # 3/3/2006
#

Are those hash signs messing me up? I just don't understand what's
going on. I set a breakpoint and it clearly shows tmpEvent.StartD ate
as 1/1/2006 and Date.Now as today's date.

Mar 3 '06 #5

<la*****@gmail. com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
If tmpEvent.StartD ate <= Date.Now.ToShor tDateString


This looks very wrong. You should compare the internal date representations
as this will prevent problems with different formats etc.

Mar 3 '06 #6

<la*****@gmail. com> wrote in message
news:11******** **************@ p10g2000cwp.goo glegroups.com.. .
The dates being posted in the database are being entered as 1/1/1900
and i know Date.Now.ToShor tDateString gives a day that says # 3/3/2006#

Are those hash signs messing me up? I just don't understand what's
going on. I set a breakpoint and it clearly shows tmpEvent.StartD ate
as 1/1/2006 and Date.Now as today's date.


It isn't the hash signs. Apples == Apples. Apples != Oranges. You are
comparing Apples to Oranges. What you see at a breakpoint is not what is
being compared. You should compare a date formatted DB field to Date.Now

Mar 3 '06 #7
<la*****@gmail. com> schrieb
If tmpEvent.StartD ate <= Date.Now.ToShor tDateString
Then

What's the data type of the StartDate property? If it' isn't String, you
should enable Option Strict.
Armin

Mar 3 '06 #8
Labelle,

As result from the answers from the others,

Try this one
\\\
If CDate(tmpEvent. StartDate) <= Date.Now 'This converts any right date in
your local setting to an internal date, which is in 100 nanoseconds ticsk
starting at ISO date 1-1-1 00:00:00
///
I hope this helps,

Cor

<la*****@gmail. com> schreef in bericht
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
I have an event listing on my website that is pulling from SQL.
Unfortunately, the listing is displaying all events, especially those
that are even 2 years old. I want to get rid of them and only display
events that are today or in the future. I need help!

Dim tmpEvents As Events
tmpEvents = New EventsMapper(). GetEvents()
Dim tmpEvent As New [Event]
Dim tmpEventListing As String
For Each tmpEvent In tmpEvents
tmpEventListing += "<font style='font-family: Verdana;
font-size: 10px;'>" & tmpEvent.StartD ate & "</font>" & " <br> " &
"<font style='font-family: Verdana; font-weight: bold; font-size:
10px;'>" & "<A href=javascript :openpopup3(" & tmpEvent.ID.ToS tring &
")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>"

If tmpEvent.StartD ate <= Date.Now.ToShor tDateString
Then
Label2.Text = tmpEventListing
Else
Label2.Enabled = False
End If
Next

This displays all the events, but does nothing for events in the past.
Can you help?

Mar 4 '06 #9
Are you sure ? IMO the date is not enclosed in # but anyway
ToShortDateStri ng returns a *string*. You shouldn't use this at all to
compare "real" dates and not strings :
If tmpEvent.StartD ate <= Date.Now Then

Also keep in mind that the date is not "entered as 1/1/1900" in the database
(assuming you have used the appropriate data type). Dates are always stored
the same internally. How they are printed depends on regional settings but a
given date has always the same internal representation.

Just make sure to compare dates to dates (and not dates to strings) so that
you compare their intela representation and not how they "look like" as text
in a particular language.

--
Patrice

<la*****@gmail. com> a écrit dans le message de
news:11******** **************@ p10g2000cwp.goo glegroups.com.. .
The dates being posted in the database are being entered as 1/1/1900
and i know Date.Now.ToShor tDateString gives a day that says # 3/3/2006
#

Are those hash signs messing me up? I just don't understand what's
going on. I set a breakpoint and it clearly shows tmpEvent.StartD ate
as 1/1/2006 and Date.Now as today's date.

Mar 6 '06 #10

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

Similar topics

2
3099
by: Russell Reagan | last post by:
In a newer version of a chess program I am writing, I have created classes that are (more or less) drop in replacements for things that used to be plain old integer or enumerated variables (colors, piece types, squares, etc.). To accomplish this, I used implicit conversions. For instance, a color used to be: typedef int Color; // and a few constants... Now a color is (paraphrased):
14
2068
by: rogerclive | last post by:
Perhaps, there is no bigger sleazy company in the entire Maple Republic ( Canada ) than Matrox Graphics Inc. I paid $100+ through my nose circa 1999 for Matrox Millenium II and Mystique. It works well under NT4.0 however, a month ago I upgraded to Win 98. Guess what? The main feature in the Matrox Inc Video cards was their desktop, and
7
1909
by: Fendi Baba | last post by:
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. .............................................................. var decimalPointDelimiter = ".";
7
4113
by: Reply Via Newsgroup | last post by:
This might sound sad... someone requesting a disertation on the 'eval' statement... but... I've been reading someone else's post - they had a huge calander like script and a handful of folk cursed the script and special attention was thrown at the fact the script used eval alot. I don't use eval alot in my scripts - but I do use it - and since I always out to learn more / improve my javascript skills, I'm curious why something I thought...
8
10020
by: Mojca | last post by:
What is formula that get days between two dates? Npr: 11.03.1998 – 1.7.2005 Thank you, Mojca
6
2031
by: Brian Raab | last post by:
I must warn you, evil script-kiddies write evil programs to flood the usenet with stupid messages in C.They probably write worms and virus programs, too. So tell the daddies of the script-kiddies to give them a good spanking, before they'll do any harm!
41
2237
by: Mark R. Dawson | last post by:
I have never used a goto statement in my code, one of the first things I was told in my software classes a number of years ago was "goto statements are evil and lead to spagetti code - do not use them". I absorbed this mantra and tell this to other people and I fully believe in it. However, I was talking to someone recently and he was saying how much he loved goto statements and how useful they were and that Microsoft had to leave them...
2
4516
by: Yog | last post by:
Is there a best way to handle various formats of dates for SQL server?. The data comes in various input files with different date formats. The ParseExact function looks like an "evil" and it doesn't seem to work for some cases. 'Date Time Stuff Dim dtarray As String() = _
24
3442
by: Larry | last post by:
Hi there: I have seen numerous postings about eval() and its evils on this forum. However, one of our developers is using it in the following way, which seems like a great use of it. Page makes Ajax request to ASP.Net web service. Web service does some data lookup and builds a string representation of a Javascript array which is then returned to the client. In the ajax callback, call to eval on the returned string and voila, ...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10373
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
10374
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
9195
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...
0
6880
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
5547
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.