Results 1 to 5 of 5

Thread: Date time separation?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    9

    Date time separation?

    Hi
    i want to separate both date and time

    what query to use
    Select * From Checkin where userid=990 And Timein=4/19/2011???(date Portion only)

    and how to retrieve time as well

    using dtp1(dtpicker)

    table=checkin
    user id (text)
    Timein (Date/Time)

    Userid Timein
    989 4/19/2011 2:58:18 PM
    990 4/19/2011 3:00:20 PM

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Date time separation?

    I don't see a VB question here. As a SQL question it is almost meaningless without knowing its context. What database for example.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    9

    Re: Date time separation?

    sorry i forgot to mention access database
    with two fields userid datatype string
    and timein datatype Date/Time
    date and time in table is saved as

    989 4/19/2011 2:58:18 PM
    990 4/19/2011 3:00:20 PM

    now i want to retrieve date like

    Code:
    txtdate.text=4/19/2011
    
    'and time 
    
    txttime.text=3:00 PM
    
    Select * From Checkin where userid=990 And Timein=Dtp1.Value
    Dtp1.Value here is the problem

  4. #4
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: Date time separation?

    The date type variable is stored internally as a double
    where the date part is the 'integer' portion and the
    time part is the fractional portion. Thus:

    Code:
    Private Sub Form_Load()
     Dim d As Date
     d = Now
     Debug.Print TimeFromDate(d)
     Debug.Print DateFromDate(d)
     Debug.Print CDbl(d)
    End Sub
    Private Function DateFromDate(d As Date) As Date
     Dim dbl As Double
     dbl = CDbl(d)
     DateFromDate = CDate(Fix(dbl)) 'get the 'integer' portion
    End Function
    Private Function TimeFromDate(d As Date) As Date
     Dim dbl As Double
     dbl = CDbl(d)
     TimeFromDate = CDate(dbl - Fix(dbl)) 'get the fractional portion
    End Function

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    9

    Re: Date time separation?

    Thanks, you solved my fore coming issue but i am facing query problem

    vbcode Code:
    1. Private Sub Cmdok_Click()
    2.  
    3.  
    4. ListView2.ListItems.Clear
    5. Set rs = New ADODB.Recordset
    6.  
    7.     With rs
    8.    
    9.         criteria = "Select * from checkinout where userid='" & ListView1.SelectedItem & "'  and timein like ' " & DTPicker1.Value & "%'"
    10.        
    11.             .Open criteria, db, 3, 3
    12.                
    13.             Do While Not .EOF
    14.            
    15.            
    16.              ListView2.ListItems.Add , , !userid
    17.            
    18.            
    19.             ListView2.ListItems(ListView2.ListItems.Count).SubItems(1) = !timetin
    20.            
    21.             .MoveNext
    22.            
    23.             Loop
    24.            
    25.             End With
    26.            
    27. Set rs = Nothing
    28.  
    29. End Sub

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