Any SQL Server T-SQL Experts?
Matt Shields
matt-urrlRJtNKRMsHrnhXWJB8w at public.gmane.org
Fri Feb 11 14:53:06 EST 2011
On Fri, Feb 11, 2011 at 2:40 PM, Raenac <raenac-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
> Try SELECT REPLACE(CONVERT(*varchar(5)*, GETDATE(), 108), ':', '')
>
>
> On Fri, Feb 11, 2011 at 2:39 PM, Matt Shields <matt-urrlRJtNKRMsHrnhXWJB8w at public.gmane.org>wrote:
>
>> On Fri, Feb 11, 2011 at 2:37 PM, Raenac <raenac-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
>>
>>> select convert(varchar,getdate(),112)+replace(convert(varchar,
>>> getdate(),108),':','')
>>>
>>> gives you YYYYMMDDHHmmss
>>>
>>> tried that?
>>>
>>> On Fri, Feb 11, 2011 at 2:15 PM, Matt Shields <matt-urrlRJtNKRMsHrnhXWJB8w at public.gmane.org>wrote:
>>>
>>>> I know this is a long shot, but are there any T-SQL experts on the list?
>>>> I
>>>> need a query that will give me date/time in the format like this
>>>>
>>>> YYYYMMDDHHmm (year, month, day, hour, minute) all with prepended zero's
>>>> if
>>>> necessary. So if the month is 02, it should appear as 02 not 2.
>>>>
>>>> For example: 201002111411
>>>>
>>>> The closest I've been able to come is the following, but it also gives
>>>> me
>>>> seconds which I don't want.
>>>>
>>>> SELECT replace(convert(varchar, getdate(),111),‘/’,”) +
>>>>
>>>> replace(convert(varchar, getdate(),108),‘:’,”)
>>>>
>>>> Also, if there's a better way than using replace, I'm good with that
>>>> too.
>>>>
>>>> -matt
>>>> _______________________________________________
>>>> Discuss mailing list
>>>> Discuss-mNDKBlG2WHs at public.gmane.org
>>>> http://lists.blu.org/mailman/listinfo/discuss
>>>>
>>>
>>>
>> Yup, figured out changing the first line to use 112 and I can do away with
>> the first replace. Still need a way to not have seconds in there.
>>
>> -matt
>>
>>
>>
>
Excellent!!! Thank you Raenac. Here's the final sql
SELECT convert(varchar, getdate(), 112) +
replace(convert(varchar(5), getdate(),108),':','')
-matt
More information about the Discuss
mailing list