CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2005
    Location
    Kisumu, KENYA. EAST AFRICA
    Posts
    88

    Question Calculating number of days from DatePicker

    Halo,

    My application captures data using date pickers. Items are taken and returned after certain intervals.
    I have code that should change the date in DTPicker2 by 21 days if DTPicker1 has been changed.

    Code:
    Private Sub   
      Dim d As String, dtp As Date
      dtp=DateAdd("d", 21, Now)
      DTPicker2.Value = dtp
    End Sub
    ONE: This code at times simply changes the value of the date bot not the month, is there a better code than this(for achieving my goal of adding 21 days to the days given)? I searched this forum and tried all the proposed ones and even tried modifying them but none seems to be working for me.

    TWO: Items should be returned on or before the DTPicker2.Value has elapsed. I want to querry the database to know what items have not been returned as at today... am stuck. Any ideas out there on how to calculate the duration an item has been out?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Calculating number of days from DatePicker

    You are adding 21 days to TODAY, not the date picked day.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Calculating number of days from DatePicker

    when querying a database I usually add one day because in date terms, if you set MyDate = "4/4/2011" It's Set to '4/4/2011 12:00am' or Midnight at the start of the day..

    When Querying a DB on Day time '4/4/2011 8:00am' is > Mydate and not < Mydate...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  4. #4
    Join Date
    Jul 2005
    Location
    Kisumu, KENYA. EAST AFRICA
    Posts
    88

    Re: Calculating number of days from DatePicker

    Quote Originally Posted by dglienna View Post
    You are adding 21 days to TODAY, not the date picked day.
    So where do I set it to pick the date on the DTPicker1? Do I have an extra line with

    Code:
    myPickDate=DTPicker1.Value

  5. #5
    Join Date
    Jul 2005
    Location
    Kisumu, KENYA. EAST AFRICA
    Posts
    88

    Smile [resolved] Re: Calculating number of days from DatePicker

    Thanks for the light bulb. This is what I did and so far it counts 21 days fine.

    Code:
    Private Sub DTPicker1_Change()
      Dim d As String, dtp As Date, myPickDate As Date
      myPickDate = DTPicker1.Value
      dtp = DateAdd("d", 21, myPickDate)
      DTPicker2.Value = dtp
    End Sub
    Last edited by iagina; April 11th, 2011 at 05:14 AM. Reason: Extra line in code

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

Featured