Solved

To emoreau

Posted on 2000-03-07
4
235 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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