Tuesday, February 14, 2012

Date and time

Hello all!
I want to create a time stamp based on the system date and system
time. The format of my timestamp should be YYYYMMDDhhmmss.
YYYY year
MM month
DD day
hh hours
mm minutes
ss seconds
Does anyone have a clue on how can I do this?
Thanks in advance,
Hugo MadureiraHere's an example:
DECLARE @.i datetime
SET @.i = CURRENT_TIMESTAMP
SELECT CONVERT(varchar(8), @.i, 112) + REPLACE(CONVERT(varchar(8), @.i, 108),
':', SPACE(0))
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Hugo Madureira" <hugomadureira@.hotmail.com> wrote in message
news:uhptUrejFHA.2644@.TK2MSFTNGP09.phx.gbl...
Hello all!
I want to create a time stamp based on the system date and system
time. The format of my timestamp should be YYYYMMDDhhmmss.
YYYY year
MM month
DD day
hh hours
mm minutes
ss seconds
Does anyone have a clue on how can I do this?
Thanks in advance,
Hugo Madureira|||Thanks a lot, it worked. That would have take me days to find that out.
Narayana Vyas Kondreddi wrote:
> Here's an example:
> DECLARE @.i datetime
> SET @.i = CURRENT_TIMESTAMP
> SELECT CONVERT(varchar(8), @.i, 112) + REPLACE(CONVERT(varchar(8), @.i, 108)
,
> ':', SPACE(0))
>|||Hi
If you use the normal datetime datatype and getdate() to populate a default.
This can then be displayed in whatever format is require on the client. If
really necessary you can use
REPLACE(REPLACE(REPLACE(CONVERT(char(19)
,mydate,120),'-'.''),SPACE(1),''),':
','') to get YYYYMMDDHHMISS format.
John
"Hugo Madureira" wrote:

> Hello all!
> I want to create a time stamp based on the system date and system
> time. The format of my timestamp should be YYYYMMDDhhmmss.
> YYYY year
> MM month
> DD day
> hh hours
> mm minutes
> ss seconds
> Does anyone have a clue on how can I do this?
> Thanks in advance,
> Hugo Madureira
>

No comments:

Post a Comment