Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

To emoreau

Posted on 2000-03-07
4
Medium Priority
?
257 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 80 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

876 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