Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IF Then With Date

    I am having trouble with the following code!

    YearField = Year(Date)

    If YearField = RS.fields("DoFYearField") Then
    response.write "Current Date " & RS.fields("DoFYearField") & "<BR>" & (YearField) & "<br>"
    Else
    response.write "Not Current Date " & RS.fields("DoFYearField") & "<BR>" & (YearField) & "<br>"
    End If

    and I make sure that the current is equal but I always get Not Current Date as the output?

    What am I doing wrong!
    Last edited by Crash1hd; 01-28-2003 at 09:28 AM.

  • #2
    New Coder
    Join Date
    Jan 2003
    Location
    Peterborough, UK
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Two things to check first:

    Change - YearField = Year(Date)
    to - YearField = Year(Date())


    If it's still not working then add a CInt to ensure data types are compatible, thus:

    YearField = CInt(Year(Date()) )

    If YearField = CInt(RS.fields("DoFYearField")) Then
    response.write "Current Date " & RS.fields("DoFYearField") & "<BR>" & (YearField) & "<br>"
    Else
    response.write "Not Current Date " & RS.fields("DoFYearField") & "<BR>" & (YearField) & "<br>"
    End If

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So all I really was missing was the CInt

    Lol

    Thankyou Very much

    Ok Next step what I am trying to achieve is that if the current date is before the event date it will post when it is if it is past the event date then it will show sorry this event has passed or something like that I can get it to check the year and month but once I try to get it to check the day it doesnt post properly if it is the 15th of january and the event happend on the 14th of febuary if I add the day field it says sorry it has already happend! even though it hasnt!

    Any help

    Thanks in advance
    Last edited by Crash1hd; 01-28-2003 at 11:24 AM.

  • #4
    New Coder
    Join Date
    Jan 2003
    Location
    Peterborough, UK
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If that makes it work, then yes!

    I always use date() or now() for date/time, so not sure of date works without the parentheses.

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So the following is what I have

    If YearField =< CInt(RS.fields("DoFYearField")) Then
    If MonthField =< CInt(RS.fields("DoFMonthField")) Then

    response.write "Current Date 0" & (MonthField) & " " & (DayField) & " " & (YearField) & "<br>Event is on " & RS.fields("DoFMonthField") & " " & RS.fields("DoFDayField") & " " & RS.fields("DoFYearField") & "<br>"
    Else
    response.write "Current Date 0" & (MonthField) & " " & (DayField) & " " & (YearField) & "<br>Event was on " & RS.fields("DoFMonthField") & " " & RS.fields("DoFDayField") & " " & RS.fields("DoFYearField") & "<br>"

    End If
    End If
    Of course this works for the following month but if its the current month and the day has passed then it still says the first cause how do you check for day only when month equals current month! once I figure that out I will also be adding TIme down to the min?


  • #6
    New Coder
    Join Date
    Jan 2003
    Location
    Peterborough, UK
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I believe you'll have to add an AND test to:

    If MonthField =< CInt(RS.fields("DoFMonthField")) Then


    So you will have:

    If MonthField =< CInt(RS.fields("DoFMonthField")) AND {and test here} Then

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Doh I had thought of useing The AND feature but I have been working with javascript to long lol cause I tried to use & and && and niether of them worked!


    Thankyou verymuch again!

    P.s. Do you know of a place that has a good reference to the different possible features do and mean for example

    = is equals to
    <> is not equals to
    > greater then
    < less then
    & I thought was and but I gues AND is and
    | is or but I may be wrong I need something that list all of the possibilitys like the one I have for javascripts!

    at

    http://www.devguru.com/Technologies/...ipt_index.html
    Last edited by Crash1hd; 01-28-2003 at 12:47 PM.

  • #8
    New Coder
    Join Date
    Jan 2003
    Location
    Peterborough, UK
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The {} were just to indicate where to insert the test.

    If MonthField = CInt(RS.fields("DoFMonthField")) And DayField = CInt(RS.fields("DoFDayField")) Then

    Should work.

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually I had to do the following

    If MonthField = CInt(RS.fields("DoFMonthField")) AND (DayField =< CInt(RS.fields("DoFDayField"))) Then

    To get it to work I had to put () around it lol again if you can check the post above yours above this one as I had changed it while you where replying

    Thankyou Very much

    Adam

    P.s. Is there a or statement or an opposite to and
    Last edited by Crash1hd; 01-28-2003 at 01:08 PM.

  • #10
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok So I put the following as the code

    If YearField =< CInt(RS.fields("DoFYearField")) Then
    If MonthField =< CInt(RS.fields("DoFMonthField")) OR MonthField = CInt(RS.fields("DoFMonthField")) AND (DayField =< CInt(RS.fields("DoFDayField"))) Then

    response.write "Current Date 0" & (MonthField) & " " & (DayField) & " " & (YearField) & "<br>Event is on " & RS.fields("DoFMonthField") & " " & RS.fields("DoFDayField") & " " & RS.fields("DoFYearField") & "<br>"
    Else
    response.write "Current Date 0" & (MonthField) & " " & (DayField) & " " & (YearField) & "<br>Event was on " & RS.fields("DoFMonthField") & " " & RS.fields("DoFDayField") & " " & RS.fields("DoFYearField") & "<br>"

    End If
    End If

    But useing that feature alows when its passed it still says is on???

  • #11
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Doh I finaly figured it out lol figures I always figure it out after awhile

    here it is

    If YearField => CInt(RS.fields("DoFYearField")) Then
    If MonthField < CInt(RS.fields("DoFMonthField")) Then
    response.write "Current Date 0" & (MonthField) & " " & (DayField) & " " & (YearField) & "<br>Event is on " & RS.fields("DoFMonthField") & " " & RS.fields("DoFDayField") & " " & RS.fields("DoFYearField") & "<br>"
    Else
    If MonthField = CInt(RS.fields("DoFMonthField")) AND (DayField =< CInt(RS.fields("DoFDayField"))) Then

    response.write "Current Date 0" & (MonthField) & " " & (DayField) & " " & (YearField) & "<br>Event is on " & RS.fields("DoFMonthField") & " " & RS.fields("DoFDayField") & " " & RS.fields("DoFYearField") & "<br>"
    Else
    response.write "Current Date 0" & (MonthField) & " " & (DayField) & " " & (YearField) & "<br>Event was on " & RS.fields("DoFMonthField") & " " & RS.fields("DoFDayField") & " " & RS.fields("DoFYearField") & "<br>"
    End If
    End If
    End If
    Last edited by Crash1hd; 01-28-2003 at 01:44 PM.

  • #12
    New Coder
    Join Date
    Jan 2003
    Location
    Peterborough, UK
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glad it's working. There 's an OR operator, in your context it would be used as:

    If condition1 OR condition2 then

  • #13
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whenever you're trying to get the Difference between dates, VBScript (and SQL!) have built in functions called DateDiff() which will solve this problem for you. I use it all the time. As a matter of fact, using that will probably shorten your code considerably.

    Have a search on google, you will find the relevant information on the following sites as well:

    http://www.w3schools.com/vbscript/func_datediff.asp

    http://msdn.microsoft.com/library/de...ctdatediff.asp

    Believe me, it's much easier than the method that you're currently employing (although I see no reason why it won't work - but that's beside the point).

    Last edited by whammy; 01-29-2003 at 03:04 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #14
    New Coder
    Join Date
    Jan 2003
    Location
    Peterborough, UK
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I aslo use datediff() with great frequency, but was just using the method above to help solve the specific problem.

  • #15
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for all the info I will check out the DateDiff() function for sure! maybe if someone where to post a small example it would make more sense quicker

    Thanks again


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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