473,382 Members | 1,647 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,382 software developers and data experts.

how to compare dates

16
I m writing some VB codes for my access database...
Now I have a table which contains a "editDate" field, its format is "26/06/2007 11:12:34 AM", then I created a form which would ask the user to input StartingDate and EndingDate... they are in the format "07/07/2007"
In my VB codes:
Expand|Select|Wrap|Line Numbers
  1. Dim myDate1 As Date
  2. Dim myDate2 As Date
  3. myDate1 = StartingDate
  4. myDate2 = EndingDate 
Then I want to compare the dates, so that to extract the records whereas its editDate is between the starting and ending dates. isnt it supposed to be:
Expand|Select|Wrap|Line Numbers
  1. If (myDate1<MyRS("editDate") AND myDate2 > MyRS("editDate")) Then
PS: another strange thing, sometimes when I input a date, it would change to some other date after itself gets updated. why?
Jul 2 '07 #1
4 12869
FishVal
2,653 Expert 2GB
I m writing some VB codes for my access database...
Now I have a table which contains a "editDate" field, its format is "26/06/2007 11:12:34 AM", then I created a form which would ask the user to input StartingDate and EndingDate... they are in the format "07/07/2007"
In my VB codes:
Dim myDate1 As Date
Dim myDate2 As Date
myDate1 = StartingDate
myDate2 = EndingDate
Then I want to compare the dates, so that to extract the records whereas its editDate is between the starting and ending dates. isnt it supposed to be:
If (myDate1<MyRS("editDate") AND myDate2 > MyRS("editDate")) Then

PS: another strange thing, sometimes when I input a date, it would change to some other date after itself gets updated. why?
Hi!

This may be caused by date format conflict.

VBA and SQL treat date in american format (#m/d/y#) no matter what is your system date format to tell nothing about date field format.

There is one (at least) tricky point.
When you pass a date to VBA or SQL which Access recognize to be in #d/m/y# format (e.g. #13/10/2007#) it is converted automatically to #m/d/y# format.
One the other hand when you pass a date smthg like #07/10/2007# assuming it in #d/m/y# format VBA and SQL treat it as #m/d/y# without letting you know it.

So, you suppose that
#25/03/2007# > #12/03/2007# = True
but it is not so bcz clever Access treats #25/03/2007# as #03/25/2007# and #12/03/2007# as #12/03/2007# and evaluates expression above to false

The solution may be:
  • to use #m/d/y# format
  • to generate dates explicitly, e.g
    Expand|Select|Wrap|Line Numbers
    1. DateSerial(Year(dteYourDate), Month(dteYourDate), Day(dteYourDate))
    2.  
Jul 2 '07 #2
NeoPa
32,556 Expert Mod 16PB
I m writing some VB codes for my access database...
Now I have a table which contains a "editDate" field, its format is "26/06/2007 11:12:34 AM", then I created a form which would ask the user to input StartingDate and EndingDate... they are in the format "07/07/2007"
In my VB codes:
Expand|Select|Wrap|Line Numbers
  1. Dim myDate1 As Date
  2. Dim myDate2 As Date
  3. myDate1 = StartingDate
  4. myDate2 = EndingDate 
Then I want to compare the dates, so that to extract the records whereas its editDate is between the starting and ending dates. isnt it supposed to be:
Expand|Select|Wrap|Line Numbers
  1. If (myDate1<MyRS("editDate") AND myDate2 > MyRS("editDate")) Then
PS: another strange thing, sometimes when I input a date, it would change to some other date after itself gets updated. why?
I tried to read the question but it doesn't actually make sense.
When posting a question here, please have the courtesy to check it before submitting, for basic sense. Sure we can guess, but it's harder and makes us work to save your time.

Your If code question refers to MyRS which we have been told nothing about.

We'd like to help, but you don't make it easy.

Fish, the M/D/Y date format is only a standard in SQL. The VBA dates work with your system settings.
Jul 2 '07 #3
FishVal
2,653 Expert 2GB
Fish, the M/D/Y date format is only a standard in SQL. The VBA dates work with your system settings.
Sorry. You are right.
Jul 2 '07 #4
NeoPa
32,556 Expert Mod 16PB
Sorry. You are right.
Apology certainly not necessary. You're post was very helpful and that basic (SQL Date) point is very important to understand :)
Jul 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows...
3
by: jrc4728 | last post by:
I have a MySQL table with the date stored in three fields as string values like this. (sorry, its imported data) str_yy str_dd str_mm ------------------------ 05 01 04 05 ...
4
by: alexis | last post by:
Hi, In a form I have the curent date <input name="datetoday" type="hidden" value="<? echo date("d/m/Y"); ?>"> and <input type=text name="datebox" size=15> The date format is d/m/Y...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
9
by: Rich | last post by:
Thanks for the Help in my previous post. I've been working on this and it's almost what I want. I want to obtain the user's current age by comparing their date of birth (user inputs) to the...
9
by: Rimuen | last post by:
Have two text form with dates i need to compare before submitting, the second should always be a date later the first one. Anyone have a script for this ?? Thanks.......
1
by: godsella | last post by:
First i have two stored procedures, i have passed the values of each one into two different arraylists of dates. how can i compare the two arraylists of dates? Thanks in advance
5
by: Tom | last post by:
It appears that you can't compare two dates in DotNet. You must use ToString and compare the strings. Is that the only reliable way? Try this: Dim dteOne As Date =...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
6
by: cd123 | last post by:
Hi, I used Date object of Javascrips to compare two dates like one is the from date and the other is to date. var obj1 = new Date(from date); var obj2 = new Date(to date); then i used...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.