---
title: "cannot be applied to operands of type 'string' and 'int'"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/143157-cannot-be-applied-to-operands-of-type-string-and-int"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "saw"
published: "2006-02-28T11:21:42.000Z"
updated: "2006-02-28T11:34:51.000Z"
replies: 2
views: 313
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/143157-cannot-be-applied-to-operands-of-type-string-and-int"
---

# cannot be applied to operands of type 'string' and 'int'

## #1 — saw, 2006-02-28T11:21Z

Jag försöker att kolla om ett datum är högst g dggr gammalt.

```
DateTime t = Convert.ToDateTime(datum);
			string sBild="";
			
		if (t >= DateTime.Now.ToShortDateString() - 6)
		{
		sBild="<Img Src=Bild/nytt1.gif width=40 height=20>";
		}
		else
		{
			sBild="";
		}
```

Jag får felmedelandet:

```
c:\inetpub\wwwroot\ASP_Net-Test\News\Webbutil.cs(31): Operator '-' 
cannot be applied to operands of type 'string' and 'int'
```

Permalänk: https://www.webforum.nu/p/143157

## #2 — inspiro, 2006-02-28T11:25Z

Det går inte att subtrahera ett datum sådär.

```
DateTime.Now.AddDays(-6)
```

Permalänk: https://www.webforum.nu/p/1772461

## #3 — saw, 2006-02-28T11:34Z

Tack för det.
Så här blev det då:

```
if (t >= DateTime.Now.AddDays(-6))
```

Permalänk: https://www.webforum.nu/p/1772466

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/143157-cannot-be-applied-to-operands-of-type-string-and-int
