| Author |
Topic |
|
sanjay5219
Posting Yak Master
240 Posts |
Posted - 2011-08-03 : 10:03:38
|
| Hi All,I need to convert 01/01/1900 01:01:00 into 01:01 AM please help |
|
|
theboyholty
Posting Yak Master
226 Posts |
Posted - 2011-08-03 : 10:11:20
|
| Have a play around with:DECLARE @D DATETIMESET @D = '01/01/1900 01:01:00'SELECT @DSELECT CONVERT(VARCHAR,@D,108)SELECT CONVERT(VARCHAR,@D,109)Neither of these will give you the AM/PM though so you could get creative and try something likeSELECT LEFT(CONVERT(VARCHAR,@D,108),5) + ' ' + RIGHT(CONVERT(VARCHAR,@D,109),2)Its hardly an elegent solution but it will work if you can't think of anything else.---------------------------------------------------------------------------------http://www.mannyroadend.co.uk The official unofficial website of Bury Football Club |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-03 : 12:42:27
|
what aboutDECLARE @D DATETIMESET @D = '01/01/1900 01:01:00'select right(convert(varchar(20),@D,100),8) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-08-08 : 09:25:43
|
| If you use front end application, do formation thereMadhivananFailing to plan is Planning to fail |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
|
|
robtop
Starting Member
9 Posts |
Posted - 2011-08-09 : 08:25:28
|
| Afternoon,I have a similar issue to this but cant seem to get these solutions to work so must be ddoing something wrong.Basically I'm trying to show a datefield (PolicyToDate) + 1 day as a text string just for the day and month e.gShow 01/01/2011 as '01 2011'I've tried several ways of doign this, none of which works exactly as I would like.If anyone has any ideas how to do this properly it would be much appreciated.Thanks a lotRob |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-09 : 09:53:01
|
quote: Originally posted by robtop Afternoon,I have a similar issue to this but cant seem to get these solutions to work so must be ddoing something wrong.Basically I'm trying to show a datefield (PolicyToDate) + 1 day as a text string just for the day and month e.gShow 01/01/2011 as '01 2011'I've tried several ways of doign this, none of which works exactly as I would like.If anyone has any ideas how to do this properly it would be much appreciated.Thanks a lotRob
just a matter ofSELECT DATENAME(mm,@date) + ' ' + DATENAME(yyyy,@date)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jcelko
Esteemed SQL Purist
547 Posts |
Posted - 2011-08-09 : 16:24:08
|
| >> I need to convert 01/01/1900 01:01:00 into 01:01 AM please help.<<Temporal data is an abstraction in SQL, not display strings. That was COBOL and mag tapes decades ago. The strings you posted do not even follow ISO-8601 display format (The only one allowed in ANSI/ISO Standard SQL).In Standard SQL, there is an EXTRACT() function. In T-SQL we can use:DECLARE silly_datetime DATETIME2(0);SET silly_datetime = '1900-01-01 01:01:00'; CAST (silly_datetime AS DATE) = '1900-01-01' CAST (silly_datetime AS TIME) = '01:01:00'--CELKO--Books in Celko Series for Morgan-Kaufmann PublishingAnalytics and OLAP in SQLData and Databases: Concepts in Practice Data, Measurements and Standards in SQLSQL for SmartiesSQL Programming Style SQL Puzzles and Answers Thinking in SetsTrees and Hierarchies in SQL |
 |
|
|
robtop
Starting Member
9 Posts |
Posted - 2011-08-10 : 04:17:10
|
| Thanks a lot Visakh, I had managed to get soemthign along those lines working but the problem I'm getting is the date text string i'm getting from this gives me 1 August & I need it to show 01 August otherwise it doesn't sort properly in the report I build from this table.Any ideas?Thanks a lot Rob |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-10 : 07:25:26
|
| for that you can just use likeSELECT RIGHT('0' + DATENAME(mm,@date),2) + ' ' + DATENAME(yyyy,@date)but if you've a front end try to do this in it as its a presentation issue------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|