473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.StartDate & "</font>" & " <br> " &
"<font style='font-family: Verdana; font-weight: bold; font-size:
10px;'>" & "<A href=javascript:openpopup3(" & tmpEvent.ID.ToString &
")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>"

If tmpEvent.StartDate <= Date.Now.ToShortDateString
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 1307
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.googlegr oups.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.StartDate & "</font>" & " <br> " &
"<font style='font-family: Verdana; font-weight: bold; font-size:
10px;'>" & "<A href=javascript:openpopup3(" & tmpEvent.ID.ToString &
")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>"

If tmpEvent.StartDate <= Date.Now.ToShortDateString
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.googlegr oups.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.StartDate & "</font>" & " <br> " &
"<font style='font-family: Verdana; font-weight: bold; font-size:
10px;'>" & "<A href=javascript:openpopup3(" & tmpEvent.ID.ToString &
")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>"

If tmpEvent.StartDate <= Date.Now.ToShortDateString
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.ToShortDateString 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.StartDate
as 1/1/2006 and Date.Now as today's date.

Mar 3 '06 #5

<la*****@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
If tmpEvent.StartDate <= Date.Now.ToShortDateString


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.googlegr oups.com...
The dates being posted in the database are being entered as 1/1/1900
and i know Date.Now.ToShortDateString 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.StartDate
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.StartDate <= Date.Now.ToShortDateString
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.googlegr oups.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.StartDate & "</font>" & " <br> " &
"<font style='font-family: Verdana; font-weight: bold; font-size:
10px;'>" & "<A href=javascript:openpopup3(" & tmpEvent.ID.ToString &
")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>"

If tmpEvent.StartDate <= Date.Now.ToShortDateString
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
ToShortDateString returns a *string*. You shouldn't use this at all to
compare "real" dates and not strings :
If tmpEvent.StartDate <= 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.googlegr oups.com...
The dates being posted in the database are being entered as 1/1/1900
and i know Date.Now.ToShortDateString 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.StartDate
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
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,...
14
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...
7
by: Fendi Baba | last post by:
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. .............................................................. var...
7
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...
8
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
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...
41
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...
2
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...
24
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...

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.