I want my database to delete data after 30 days of being saved SQL - RAZOR

1

(Use RAZOR) What I need is for my database to delete ROWS created 30 days ago, the creation date I am saving in a Datetime type field. So far I can only subtract and obtain the day address, for example:

var Fecha = solicitud.fechainicio - DateTime.Now;

In this way I obtain the difference of days, hours and minutes between the insertion and the current date. but at the time of trying to execute some type of code by @if(Fecha>=30){AQUI IRIÁ LA SENTENCIA SQL PARA ELIMINAR.}

I miss the following error:

El operador '>=' no se puede aplicar a operandos del tipo 'System.TimeSpan' y 'int '

    
asked by Atejada 02.10.2017 в 15:10
source

1 answer

4

You can not operate with different types, that is, you can not compare a TimeSpan and a int , to do it you must convert the 2 in the same type.

Using the following code TotalDays is giving you a type double that you can compare to 30 :

@if((DateTime.Now - Fecha).TotalDays >= 30){ CÓDIGO }

Subtracting 2 types DateTime always returns a type TimeSpan and not a DateTime as expected.

    
answered by 02.10.2017 / 15:18
source