Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert date
Message
De
05/05/2014 12:25:55
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01599545
Message ID:
01599568
Vues:
44
>>>>>>We've got a data file that has dates in 'dd-mm-yyyy (time)' format (and coming in as a string) and need them in 'standard amurican' 'mm-dd-yyyy (time)'.
>>>>>>
>>>>>>What's the best way to do this conversion?
>>>>>
>>>>>Are you looking to do the conversion in SSIS or something? How is the file getting loaded?
>>>>>
>>>>>Or is it stored in the table as a string in that format?
>>>>
>>>>Stored as a string
>>>
>>>Try
>>>
>>>
>>>DECLARE @t TABLE (dt VARCHAR(30))
>>>
>>>INSERT INTO @t (dt)
>>>VALUES ('30-10-2014')
>>>	,('13-12-2013')
>>>
>>>SELECT dt
>>>	,convert(DATE, dt, 105) AS [Real Date]
>>>FROM @t
>>
>>Same "date and/or time from character string" error
>
>Post all samples in that column and change it to be
>
>case when ISDATE(dt) = 0 then NULL else convert(date, dt, 105) end as [Real Date]
>
>The above assumes consistent format dd-mm-yyyy

The (time) in the original post was to mean that these were datetime fields (essentially).
In other words, I've got '17/06/09 01:41:00' as an example.
I need '2009-06-17 01:41:00'
"You don't manage people. You manage things - people you lead" Adm. Grace Hopper
Pflugerville, between a Rock and a Weird Place
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform