Date Comparison Problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Date Comparison Problem

  1. #1
    Join Date
    Nov 2004
    Location
    Delhi,India
    Posts
    27

    Question Date Comparison Problem

    Please Help me...
    this code is not working well:

    If CDate(txtDeliveryDate) < Format(CDate(Date), "dd/mm/yyyy") Then
    MsgBox "Date should be greater than or equal to today's Date."
    Exit Sub
    End If

    what should be modified?
    Sachin Jain

    WhatEver You Do, Do It Excellent.
    www.xmen81.blogspot.com

  2. #2
    Join Date
    Dec 2004
    Location
    Israel
    Posts
    69
    Hi,

    You did not say what was not working but here are a few comments:
    1) CDate(txtDeliveryDate) is a Date data type while Format(CDate(Date), "dd/mm/yyyy") is a variant string.
    2) Try removing the Format function since Date is the systems date without the hour part (data type variant date).
    3) When comapring dates I always like to use the DateDiff function.

    In short try:
    If CDate(txtDeliveryDate) < Date Then
    Or:
    If DateDiff("s", Date, CDate(txtDeliveryDate)) < 1 Then 'one second intercal.
    Elad
    Shareware Authors Guide - www.home-programming.com

  3. #3
    Join Date
    Nov 2004
    Location
    Delhi,India
    Posts
    27
    Originally posted by selad
    When comapring dates I always like to use the DateDiff function.

    In short try:
    If CDate(txtDeliveryDate) < Date Then
    Or:
    If DateDiff("s", Date, CDate(txtDeliveryDate)) < 1 Then 'one second intercal.
    Thanks...
    but I have tried all this stuff and my problem is that i want the user must enter the date in 'dd/mm/yyyy' format and system date can be in any format ('dd/mm/yyyy' or 'mm/dd/yyyy').
    So how to check whether entered date is small or large than system date?
    Sachin Jain

    WhatEver You Do, Do It Excellent.
    www.xmen81.blogspot.com

  4. #4
    Join Date
    Dec 2004
    Location
    Israel
    Posts
    69
    Formats and values are two different things. Both 1 and 1.00 have the same value of one. The system date have the value of the current date regardless of the format it is presented in. The way the CDate() function works depaneds on the systems setting so you must know what will be the output of CDate(txtDeliveryDate). While 12/31/2004 will always be the 31st of December, 12/1/2004 can be 12 January or December first.

    Maybe it will be more safe to take the txtDeliveryDate string and break it for its parts and then build it in the dd/mmm/yyyy format (01/Dec/2004) which have only one meening.

    HTH
    Elad
    Shareware Authors Guide - www.home-programming.com

  5. #5
    Join Date
    Nov 2004
    Location
    Delhi,India
    Posts
    27

    Red face

    Okay...I will do that boring task....
    Sachin Jain

    WhatEver You Do, Do It Excellent.
    www.xmen81.blogspot.com

  6. #6
    Join Date
    Dec 2004
    Location
    Israel
    Posts
    69
    Just before you close your eyes please let my know how you solved the problem.
    Elad
    Shareware Authors Guide - www.home-programming.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center