473,324 Members | 2,535 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,324 software developers and data experts.

DateTime and remove days

MA
Hi all!

I use datetime to navigate in a calendar i´ve made. There is no problems
navigating forward (AddDays()), but how do i remove days from DateTime? I
would love to have something like this:

DateTime start = DateTime.Today;
if(forward)
start = start.AddDays(6)
else
start = start.RemoveDays(6);

This does not exists, but is there something similar somewhere? Any ideas?

/Marre
Nov 16 '05 #1
2 19243
Hi Marre,

Same way, you just add a negative number.

int days = 6;

DateTime start = DateTime.Today;
if(forward)
start = start.AddDays(days)
else
start = start.AddDays(-days);
--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
MA
Ahhh....it feels like my head are filled with bran flakes right now ;)

Thanks Morten!
Nov 16 '05 #3

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

Similar topics

4
by: John Hunter | last post by:
>>> from datetime import date >>> dt = date(1005,1,1) >>> print dt.strftime('%Y') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: year=1005 is before 1900; the...
3
by: bredal Jensen | last post by:
Hello gurus, I'm building a small booking system and i have come accross quiet a tedious pitfall. "I need to make sure that people do not book for tomorrow when todays time is greater or...
2
by: PK9 | last post by:
I have a loop where I need to calculate a series of dates based on: 1) a start date (DateTime variable) 2) a number of days (integer variable) I need to take the start date, then add the number...
9
by: scott | last post by:
I have a field with datetime values like below LISTING 1. Can someone help me write code strip the time part so only values like "7/15/2005" will be left. Note - We must be able to strip dates...
10
by: David P. Donahue | last post by:
Can anyone think of an easy way to take two DateTime values and calculate, with double precision, how many semi-monthly (the first and the fifteenth) pay periods occur between them? I started...
5
by: Lad | last post by:
Hello, what is the best /easest way how to get number of hours and minutes from a timedelta object? Let's say we have aa=datetime.datetime(2006, 7, 29, 16, 13, 56, 609000)...
4
by: Greg Scharlemann | last post by:
I have a series of records in a database. When each record is stored, the datetime is logged: $date = date("Y-m-d H:i:s"); Prior to adding a new record to the database, I want to run a query to...
5
by: mroeloffs | last post by:
Hi I have a time in microseconds, for example 0x8C905CBA7F84AF4. I want this to a normal view in hh:mm:ss DD:MM:YYYY. I tried with datetime, but it only takes a max of 1000000 microseconds is there...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: 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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.