473,698 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(sS QL, cnn)

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

Nov 17 '05 #1
2 1834
"Duppypog" <du******@nospa m.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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(sS QL, cnn)

Dim pwEx As DateTime = cmd.ExecuteScal ar
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*****@spammi ngisevil.bad> wrote in message
news:un******** ******@TK2MSFTN GP12.phx.gbl...
"Duppypog" <du******@nospa m.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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(sS QL, cnn)

Dim pwEx As DateTime = cmd.ExecuteScal ar
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
2408
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. http://www.aspfaq.com/show.asp?id=2023 Now I am facing another problem. I have to get data between two dates. That dates user has to provide and in
2
1587
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
3338
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
2067
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 Integer. Seems kinda not nice - is there a better way? Thanks
12
5557
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 date. Example: Jun 15 How would I go about comparing that to a different date? The purpose of my program is to load a webpage and see if the content on the front page is fresh or stale as in older than a few days. Any help in the right direction...
2
4141
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 out for each what the day of the year was and subtracting the two, this worked fine until the new year.. now i have dates from 2006 and todays date of 2007 and obviously cant use the day of the year function as the 2007 date is less than the 2006...
4
2350
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 user will input dates using the combo box like cboyear,cboday and cbomonth. What SQL statement or quey should I write to compare it to the database. The database has already have value in dates. I want to compare the input date to the database.......
2
1982
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. Thanks, Dante
4
2355
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 = CDate(MydateString) ''it is highlighted in this line.. txtActCode = Mydate i don't know what's wrong with this one..
0
8612
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
9032
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
8905
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
8880
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...
1
6532
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
5869
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
4373
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...
1
3053
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
2008
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.