Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update a date part
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01059700
Message ID:
01059776
Vues:
11
This message has been marked as the solution to the initial question of the thread.
You can use a combination of DATEADD() and DATEDIFF() functions to perform what you are trying to do. Basically the code below calls the DATEDIFF function to return the time portion as the number of milliseconds, then calls the DATEADD function to add the number of millisec's to the date. This assumes that you always want to add the time portion from @settime to the @newdate variable and the time portion of @newdate is always 00:00:00.
DECLARE @settime DATETIME,
        @newdate DATETIME,
        @result  DATETIME

SELECT @settime = '1/1/1900 9:10:48 AM',
       @newdate = '7/13/2005'


SELECT @result = DATEADD(ms,DATEDIFF(ms,'01/01/1900',@settime),@newdate)
PRINT @result
Kurt

>DATEPART selects the part of the date to extract, as does Day, Month, and Year. Is there a way to update a datetime field so that the original is not changed except for the part that needs to be? For example, if @settime = 1/1/1900 9:10:48 AM and I wanted to update it to 7/13/2005 9:10:48 AM, is there a set-based command that would do that?
>
>All help is appreciated.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform