+ Reply to Thread
Results 1 to 5 of 5

Thread: If statement with Date

  1. #1
    Registered User
    Join Date
    08-31-2011
    Location
    Tokyo
    MS-Off Ver
    Excel 2010
    Posts
    46

    Question If statement with Date

    Hello,

    I don't understand how it works, can someone check my syntax. It does not give any error but it won't do what I expect :

    data_date/data_time are a Date Type, date_start and time_start too.
    When I have checked in the debug mode, the data_date and data_time has the same value and should go inside the if statement.

        
    If data_date = date_start And data_time = time_start Then
       index_start = 10
    End If
    Thank you in advance.
    Last edited by oro77; 01-25-2012 at 08:07 PM. Reason: solved!

  2. #2
    Valued Forum Contributor dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    New Delhi, India
    MS-Off Ver
    Excel 1997, 2000, XP, 2003, 2007, 2010
    Posts
    2,406

    Re: If statement with Date

    ok...
    while in debug mode.. what is the value showing for date_start and time_start...

    Condition says... if data_date equals date_start and data_time equals time_start.. then it will go inside the if statement.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey
    +919810929744
    dilipandey@gmail.com

  3. #3
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,155

    Re: If statement with Date

    maybe...

    If DateDiff("d", data_date , date_start )<0 and DateDiff("s", data_time , time_start )<0 then
       index_start = 10
    End If
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

  4. #4
    Registered User
    Join Date
    08-31-2011
    Location
    Tokyo
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: If statement with Date

    @dilipandey The values are the same in the debug mode.

    @pike Thank you very much, I did not know this function, it worked with :

    If DateDiff("d", data_date , date_start )= 0 and DateDiff("n", data_time , time_start )= 0 then
       index_start = 10
    End If

  5. #5
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,155

    Re: If statement with Date

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0