Autor Beitrag
schani
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 39



BeitragVerfasst: So 29.07.07 12:58 
Hallo,


folgendes Problem.

Ich habe eine DateTime Variable und eine int Variable.
In der DateTime Variable versteckt sich,wie sollte es auch anders sein, ein Datum.
In der int Variable stehen die Tage die ich von der DateTime Variable abziehen möchte.

Doch wie genau bekomme ich das hin, hab schon alles mögliche durchprobiert.
Hat vielleicht mal jemand nen Tipp?

Gruß

Schani
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 29.07.07 13:11 
DateTime besitzt die AddDays-Methode, welche auch negative Werte annimmt, um Tage abzuziehen.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
schani Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 39



BeitragVerfasst: So 29.07.07 13:45 
ok, vielen Dank!
schani Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 39



BeitragVerfasst: So 29.07.07 20:18 
ok, jetzt stellt sich für mich das nächste Problem.

die zahl die ich habe ist ja positiv. wie bekomme ich die jetzt negativ?

Schani
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 29.07.07 21:02 
Ein Minuszeichen davor? :gruebel:

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: So 29.07.07 21:02 
user profile iconschani hat folgendes geschrieben:
ok, jetzt stellt sich für mich das nächste Problem.

die zahl die ich habe ist ja positiv. wie bekomme ich die jetzt negativ?

Schani

z.B. ein Minus davor setzen? ;)
dtg = dtg.AddDays(-tage); (ausm Kopp)
schani Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 39



BeitragVerfasst: Mo 30.07.07 08:01 
kann ich vor eine variable einfach ein - setzen?
schani Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 39



BeitragVerfasst: Mo 30.07.07 08:28 
mit dem minus davor klappt leider nicht, das ergebnis ist dann immer 0!



hier mal ein bischen Code;
ausblenden C#-Quelltext
1:
2:
3:
// in wert1 steht das aktuelle datum!
DateTime wert2;
wert2 = wert1.AddDays(Convert.ToInt16(-numericUpDown3.Value));


Schani
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Mo 30.07.07 08:50 
Bei mir funktioniert das einwandfrei. Sicher, dass da nicht noch was anderes dazwischen steht? Und dass Du wert1 richtig initialisiert hast?
Deichkind_228
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Mo 30.07.07 09:40 
multipliziere den Integer doch einfach mit -1.
Oder habe ich was falsch verstanden?
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Mo 30.07.07 10:41 
@schani
Ich könnte mir vorstellen, dass die Reihenfolge von Minus und Convert nicht sauber ist. Mit einfacherer Konvertierung und mit den anderen Hinweisen ergibt sich also etwa so etwas:
ausblenden C#-Quelltext
1:
wert2 = wert1.AddDays((-1)*(int)numericUpDown3.Value);					

Jürgen