dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Time manipulation

  1. #1
    Join Date
    Aug 2000
    Location
    South Africa
    Posts
    195

    Time manipulation

    Hi

    Dumn question.

    I want to do certain maths with time eg:
    User inputs a starting time. I want to add an amount to that field
    like 30 minutes or 5 hours - whatever.
    How do I do that in VB?

    Any help will be appreciated

  2. #2
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    Code:
    Private Enum mtModTime
        mtSeconds = 1
        mtMinutes = 2
        mtHours = 3
        mtDays = 4
        mtWeeks = 5
        mtMonths = 6
        mtQuarters = 7
        mtYears = 8
    End Enum
        
    Private Function ModTime(ByVal When As Date, ByVal HowMuch As Double, Optional ByVal WhatPeriod As mtModTime = mtMinutes) As Date
        Dim strPeriod As String
        Select Case WhatPeriod
        Case 1
            strPeriod = "s"
        Case 2
            strPeriod = "n"
        Case 3
            strPeriod = "h"
        Case 4
            strPeriod = "d"
        Case 5
            strPeriod = "ww"
        Case 6
            strPeriod = "M"
        Case 7
            strPeriod = "q"
        Case 8
            strPeriod = "yyyy"
        End Select
        ModTime = DateAdd(strPeriod, HowMuch, When)
    End Function
    Here is a simple function that allows you to pass in a date, how much to add (negative numbers subtract) and what interval to modify by.
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Sorry: should have been 5 stars..

    But my finger clicked too fast, and caught the 4...
    So, here the missing star:

    .....................*
    ..................*....*
    ...............*..........*
    ..................*....*
    .....................*

    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)