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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Past date calculation

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.

• 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...
• 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

' Subtract 38 Days
[/code]

• 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...
:
• 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
:
: ' Subtract 38 Days
: [/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?
• 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
: :
: : ' Subtract 38 Days
: : [/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.