472,378 Members | 1,234 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Need help comparing dates

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 & "'"
cmd = New OleDbCommand(sSQL, cnn)

Dim pwEx As DateTime = cmd.ExecuteScalar
If pwEx.ToString("d") > DateTime.Today Then

Nov 17 '05 #1
2 1731
"Duppypog" <du******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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 & "'"
cmd = New OleDbCommand(sSQL, cnn)

Dim pwEx As DateTime = cmd.ExecuteScalar
If pwEx.ToString("d") > DateTime.Today Then


Part of the problem may be the string conversion you are doing. At that
point, and without strong typing, it may be comparing string lengths.

The problem with dates and times is that they are just that - not just
dates, but also times. I would try something like this, if you are trying to
do a date comparison:

Dim FirstDate as DateTime
FirstDate = DateSerial(pwEx.Year, pwEx.Month, pwEx.Day)
TodayDate = DateSerial(Now.Year, Now.Month, Now.Day)
'this will give both a time of 12:00 AM, so only dates are compared
if pwEx > TodayDate then
'do stuff
End if
Nov 17 '05 #2

THANK YOU!!
"Richard K Bethell" <so*****@spammingisevil.bad> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
"Duppypog" <du******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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 & "'"
cmd = New OleDbCommand(sSQL, cnn)

Dim pwEx As DateTime = cmd.ExecuteScalar
If pwEx.ToString("d") > DateTime.Today Then


Part of the problem may be the string conversion you are doing. At that
point, and without strong typing, it may be comparing string lengths.

The problem with dates and times is that they are just that - not just
dates, but also times. I would try something like this, if you are trying

to do a date comparison:

Dim FirstDate as DateTime
FirstDate = DateSerial(pwEx.Year, pwEx.Month, pwEx.Day)
TodayDate = DateSerial(Now.Year, Now.Month, Now.Day)
'this will give both a time of 12:00 AM, so only dates are compared
if pwEx > TodayDate then
'do stuff
End if

Nov 17 '05 #3

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

Similar topics

4
by: F | last post by:
Hi I have posted the question few days back about problem in inserting the dates in SQL server and thankful to them who replied. That was solved and this is a nice solution....
2
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...
2
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
13
by: **Developer** | last post by:
I need to sort the columns of a ListView. Some columns contain dates and others contain integers. What I did once before is in the Compare method I tried date and if that failed I did...
12
by: colincolehour | last post by:
I am new to Python and am working on my first program. I am trying to compare a date I found on a website to todays date. The problem I have is the website only shows 3 letter month name and the...
2
by: cyber100 | last post by:
Is there an easy way to calculate how many days between two dates.. i have two dates and want to work out how many days between them, i have a static date and was getting todays date then working...
4
by: cheryl | last post by:
I am using the PHP.MYSQL and Apache server application in developing my website. I have problem in comparing dates. Website has room reservation, the user will check first the room availability. The...
2
by: dantebothermy | last post by:
Is there a simple way to subtract the time from a datetime field, so when I compare dates, I'm always comparing the dates at 12:00 am? I'd really prefer not to convert all my dates to strings. ...
4
by: jupi13 | last post by:
i have this code..i don't know what where is the error in this one..it says data type mismatch..... Dim Mydate As Date Dim MydateString As String MydateString = "Text1.Text" Mydate =...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.