Past date calculation - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Past date calculation

VOmigrantVOmigrant Posts: 24Member
Hi, please help, can anyone share a good subroutine to calculate a past date from a date variable? say if I want to find out what the date was 25 months ago or 38 days ago from today. Thanks.

Comments

  • brkevrbrkevr Posts: 1Member
    : Hi, please help, can anyone share a good subroutine to calculate a past date from a date variable? say if I want to find out what the date was 25 months ago or 38 days ago from today. Thanks.
    :
    :
    You can use Datediff function for this situation.In reality the method you demand depends on your requirements...
  • iwilld0itiwilld0it Posts: 1,134Member
    : Hi, please help, can anyone share a good subroutine to calculate a past date from a date variable? say if I want to find out what the date was 25 months ago or 38 days ago from today. Thanks.
    :
    :
    The .NET date object has built in functions ...

    [code]
    ' Get Current Date
    Dim dt As Date = Date.Now.Date

    ' Subtract 25 Months
    dt = dt.AddMonths(-25)

    ' Subtract 38 Days
    dt = dt.AddDays(-28)
    [/code]


  • VOmigrantVOmigrant Posts: 24Member
    : : Hi, please help, can anyone share a good subroutine to calculate a past date from a date variable? say if I want to find out what the date was 25 months ago or 38 days ago from today. Thanks.
    : :
    : :
    : You can use Datediff function for this situation.In reality the method you demand depends on your requirements...
    :
    Thank you Brkevr for your comments.
  • VOmigrantVOmigrant Posts: 24Member
    : : Hi, please help, can anyone share a good subroutine to calculate a past date from a date variable? say if I want to find out what the date was 25 months ago or 38 days ago from today. Thanks.
    : :
    : :
    : The .NET date object has built in functions ...
    :
    : [code]
    : ' Get Current Date
    : Dim dt As Date = Date.Now.Date
    :
    : ' Subtract 25 Months
    : dt = dt.AddMonths(-25)
    :
    : ' Subtract 38 Days
    : dt = dt.AddDays(-28)
    : [/code]
    :
    :
    :
    Hi Iwilld0it, you know what? you really have made my day, thank you very much, that's exactly what I was looking for and it works. Just how did you figure that out?
  • iwilld0itiwilld0it Posts: 1,134Member
    : : : Hi, please help, can anyone share a good subroutine to calculate a past date from a date variable? say if I want to find out what the date was 25 months ago or 38 days ago from today. Thanks.
    : : :
    : : :
    : : The .NET date object has built in functions ...
    : :
    : : [code]
    : : ' Get Current Date
    : : Dim dt As Date = Date.Now.Date
    : :
    : : ' Subtract 25 Months
    : : dt = dt.AddMonths(-25)
    : :
    : : ' Subtract 38 Days
    : : dt = dt.AddDays(-28)
    : : [/code]
    : :
    : :
    : :
    : Hi Iwilld0it, you know what? you really have made my day, thank you very much, that's exactly what I was looking for and it works. Just how did you figure that out?
    :

    I've been programming .NET professionally for nearly 4 years, so you tend to pick up little tricks here and there.

Sign In or Register to comment.