Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Previous date
Message
 
 
À
11/10/2011 08:50:56
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Divers
Thread ID:
01526025
Message ID:
01526026
Vues:
40
>Hi
>
>I'm being passed a date via a csv file.
>
>I want to insert into my database the previous October 1st of that date minus 4 years.
>
>So if my date is 1st January 2011 I'd want the 1st October 2006
>
>Any ideas on how I could get that.
>
>Thnaks

Do you just want to subtract 4 years from current date?

If so,
declare @PrevDate date
set @PrevDate = dateadd(year, -4, cast(CURRENT_TIMESTAMP as DATE)) -- SQL Server 2008+
If you always want October 1, then
select CONVERT(datetime,ltrim(year(CURRENT_TIMESTAMP)-4) + '1001') as PreviousDate
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform