473,320 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Date functions in c#

Hi,

Please help on date functions in C#.

I would like to know the relevant exampl to retrieve
2 weeks before date from the current date,
1 month before date from the current date and number of days.
2 months before date from the current date and number of days.
3 months before date from the current date and number of days.
8 months before date from the current date and number of days.
1 year before date from the current date and number of days.

Pls help...

Regards,
Krian
Nov 16 '05 #1
5 60020
Hi! You can use someting like

DateTime dt = DateTime.Today.AddMonths(-2).AddDays(-3);

//Today 2 months before and 3 days

or

DateTime dt = DateTime.Today.AddYears(-1).AddMonths(-2).AddDays(-3);

//One year , two months and 3 days before.

"Kiran" <ki**************@yahoo.com> wrote in message
news:9d**************************@posting.google.c om...
Hi,

Please help on date functions in C#.

I would like to know the relevant exampl to retrieve
2 weeks before date from the current date,
1 month before date from the current date and number of days.
2 months before date from the current date and number of days.
3 months before date from the current date and number of days.
8 months before date from the current date and number of days.
1 year before date from the current date and number of days.

Pls help...

Regards,
Krian

Nov 16 '05 #2
You should take a look at the System.DateTime and System.TimeSpan
documentation.

Bruno.

"Kiran" <ki**************@yahoo.com> a écrit dans le message de news:
9d**************************@posting.google.com...
Hi,

Please help on date functions in C#.

I would like to know the relevant exampl to retrieve
2 weeks before date from the current date,
1 month before date from the current date and number of days.
2 months before date from the current date and number of days.
3 months before date from the current date and number of days.
8 months before date from the current date and number of days.
1 year before date from the current date and number of days.

Pls help...

Regards,
Krian

Nov 16 '05 #3
"Kiran" <ki**************@yahoo.com> wrote in message
news:9d**************************@posting.google.c om...
Please help on date functions in C#.


Have a look at the DateTime object, then its AddDays, AddWeeks, AddMonths
and AddYears methods. To go back in time, you just "add" a negative amount
of units.

Nov 16 '05 #4
Have you looked at all the Add* methods in the DateTime structure. Just
pass a negative value if you want dates before the specified date.

"Kiran" <ki**************@yahoo.com> wrote in message
news:9d**************************@posting.google.c om...
Hi,

Please help on date functions in C#.

I would like to know the relevant exampl to retrieve
2 weeks before date from the current date,
1 month before date from the current date and number of days.
2 months before date from the current date and number of days.
3 months before date from the current date and number of days.
8 months before date from the current date and number of days.
1 year before date from the current date and number of days.

Pls help...

Regards,
Krian

Nov 16 '05 #5

"Kiran" <ki**************@yahoo.com> wrote in message
news:9d**************************@posting.google.c om...
Hi,

Please help on date functions in C#.

I would like to know the relevant exampl to retrieve
2 weeks before date from the current date,
1 month before date from the current date and number of days.
2 months before date from the current date and number of days.
3 months before date from the current date and number of days.
8 months before date from the current date and number of days.
1 year before date from the current date and number of days.


DateTime.AddXXX

EG current date minus one month and 6 days.

DateTime.Now.Date.AddMonths(-1).AddDays(-6)

David


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Luis Pedro | last post by:
Hi there, Can anyone tell me if there is any time and date standard functions for C++ and, if so, were can I find documentation about it? If such functions do not exist, any hint of what library...
1
by: sylvian stone | last post by:
Hi, I've used standard date functions in the past, but need to create something a little different, as I am working on an investment calculator. What I need to do is validate two dates, and...
1
by: shaun | last post by:
I need to calculate a duration in seconds between 1 January 1970 and an arbitrary date (e.g today) within an xslt transform which gives the same answer as the time.h functions would in C. I can use...
4
by: Russell | last post by:
I have an assignment that I have to complete. I have to write a windows app in C#. Here is the spec: 1/ Date Comparison Build a program that will find the number of days between two dates. You...
3
by: IntraRELY | last post by:
I have the following function, Notice how I am passing the dateInterval as a string. What is the correct way to pass "DateInterval.Year" as a variable to a function? TIA, Steve Wofford...
1
by: Newbie | last post by:
I need the following functions using the standards for Week Numbering IE Week one is the first week with a thursday in it. getWeekStartDate( WeekNum as Integer , YearNumber as Integer ) as Date...
1
by: madhu | last post by:
I want db2 date functions and what is the diffrence between the oracle date functions and db2 date functions?
5
by: tombarth11 | last post by:
I have an Access 2003 SP2 Application in which I split the data base into 2 files: data-only.mdb and interface.mdb. I then "compiled" the interface file to a .mde file. Both files are on a server....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.