Results 1 to 12 of 12

Thread: Compare year together with month

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908

    Date and time

    Is there a function to compare date with time, i have month(),year().etc what about a specific date? like xx()<=02/2/2006

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Compare year together with month

    You can use DateDiff to compare Dates, or Dateadd to add hours, days, months..etc
    DateDiff Example: Find the diff in days between 2 dates..
    Code:
        Dim Ld As Date
        Ld = #12/8/2005#
        MsgBox DateDiff("d", Ld, Date) ' "d" = Days

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908

    Re: Compare year together with month

    but if i want to compare specific month WITH year i put d (as day) is ok?

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Date and time

    Would you elaborate? Compare date with time?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Compare year together with month

    Quote Originally Posted by Goh
    but if i want to compare specific month WITH year i put d (as day) is ok?
    I don't understand , write some code so I can see what you're trying to do.
    Last edited by jcis; Feb 1st, 2006 at 11:43 PM.

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Compare year together with month

    You can use.. Day(Date), for days.
    Also, Format(Date, "mmyy") will show you month and year (without days)

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Date and time

    There are several date/time functions.

    DateDiff
    DateAdd
    Hour
    Minute
    Second
    '...
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Compare year together with month

    Threads merged.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908

    Re: Compare year together with month

    sorry guys ...actually i only wanted to compare a certain date...as in only the
    like any date that is greater or equals than 01/01/2005 ..something like that

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908

    Re: Compare year together with month

    by the way am using sql statement ... passing query in vb..

    dim DateRef as date
    DateRef="01/01/2005"

    .
    .
    sql = sql & "and DateDiff("d", DateFromRecordset, DateRefer)<0 ..."

    but how am i going to amend the code 'd' ?is the above correct?
    Last edited by Goh; Feb 2nd, 2006 at 01:24 AM.

  11. #11
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Compare year together with month

    then you can use the datediff functions, but why dont you post the code here, so that, we can help you properly without wasting too many posts
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908

    Re: Compare year together with month

    i want to retrieve records which dated 01/02/2005 and later.....the database uses smalldatetime like 16/12/1999 6:21:00 PM..

    i think should use "y" ya? cause i only want month and year after the one above..

    The actual problem is that if i use Year() and month() separately, things will not go right.
    Last edited by Goh; Feb 2nd, 2006 at 02:04 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width