y****9 发帖数: 144 | 1 Googled and tested for a while, comp up with this method:
select cast(datepart(yy, getdate()) as varchar) + '-' +
cast(datepart(mm, getdate()) as varchar) + '-' +
cast(datepart(dd, getdate()) as varchar) + ' ' +
cast(datepart(hh, getdate()) as varchar)
Not sure this is the best idea in SQL Server. in Oracle it is easy:
select to_char('YY-MM-DD HH24', sysdate) from dual;
any suggestion? I am working on a query which need this conversion
Thanks, | s**m 发帖数: 1564 | 2 select substring(convert(char(23), getdate(), 120), 3,11)
select replace(substring(convert(char(23), getdate(), 120), 3,11), '-', '_')
[发表自未名空间手机版 - m.mitbbs.com]
【在 y****9 的大作中提到】 : Googled and tested for a while, comp up with this method: : select cast(datepart(yy, getdate()) as varchar) + '-' + : cast(datepart(mm, getdate()) as varchar) + '-' + : cast(datepart(dd, getdate()) as varchar) + ' ' + : cast(datepart(hh, getdate()) as varchar) : Not sure this is the best idea in SQL Server. in Oracle it is easy: : select to_char('YY-MM-DD HH24', sysdate) from dual; : any suggestion? I am working on a query which need this conversion : Thanks,
| s**********o 发帖数: 14359 | 3 对啊,有现成的,还一个一个的转换,101,102,103,一直数下去 | y****9 发帖数: 144 | 4
This works better for my purpose. Thank you!
【在 s**m 的大作中提到】 : select substring(convert(char(23), getdate(), 120), 3,11) : select replace(substring(convert(char(23), getdate(), 120), 3,11), '-', '_') : : [发表自未名空间手机版 - m.mitbbs.com]
|
|