Solved

To emoreau

Posted on 2000-03-07
4
241 Views
Last Modified: 2010-05-02
emoreau,
Is it possible to break up the Minute,Hour,Day,Month & Year into
seperate textboxes.From your previous answer to my Date subtract question.
Thanks
Dave Steers
0
Comment
Question by:dsteers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2590948
Sure thing, you can use the.. hold on to ya hat now... the Year(Date), Month(Date), Day(Date), Hour(Date), Minute(Date) functions. For example...

  Me.Caption = Year(Now)       'shows the year number
  Me.Caption = Month(Now)    'shows the month number
  Me.Caption = Day(Now)        'shows the day number
  Me.Caption = Hour(Now)      'shows the hour number
  Me.Caption = Minute(Now)   'shows the minute number
  Me.Caption = Second(Now)  'guess what?
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 20 total points
ID: 2591607
Thanks for the points!
0
 

Author Comment

by:dsteers
ID: 2603578
Guys,
Using the following code how do I seperate the Day,Month & Year into
seperate textboxes so that they can be entered by the user.
I.e 2 Day textboxes,2 Month textboxes & 2 Year textboxes.
Thanks

Code (thanks to emoreau)

Option Explicit

Private Sub Command1_Click()
Dim dtm1 As Date
Dim dtm2 As Date
Dim lngDiff As Long
Dim lngDays As Long
Dim lngHours As Long
Dim lngMinutes As Long

    dtm1 = "2000/03/08 13:40"
    dtm2 = "2000/03/09 2:00"
     
    'Returns number of minutes
    lngDiff = DateDiff("n", dtm1, dtm2)
     
    'Extract days
    If lngDiff > (24 * 60) Then
        lngDays = Int(lngDiff / (24 * 60))
        lngDiff = lngDiff - (lngDays * 24 * 60)
    End If
     
    'Extract Hours
    If lngDiff > 60 Then
        lngHours = Int(lngDiff / 60)
        lngDiff = lngDiff - (lngHours * 60)
    End If
     
    'Extract Minutes
    lngMinutes = lngDiff
     
    MsgBox "Difference between dates: " & _
           lngDays & " days, " & _
           lngHours & " hours and " & _
           lngMinutes & " minutes."
End Sub

Thanks
Dave Steers
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2604469
You can use the CDate to build your date:

    dtm1 = CDate(txtYear1 & "/" & txtMonth1 & "/" & txtDay1 & " " & txtHour1 & ":" & txtMinute1)
    dtm2 = CDate(txtYear2 & "/" & txtMonth2 & "/" & txtDay2 & " " & txtHour2 & ":" & txtMinute2)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question