0

I am trying to achieve this formt from sql server. I have tried with various things but not able to achieve this Ultimately this should be a string datatype

 '23 Apr, 2018 2:59 PM'

I am trying to achieve this as below:

CONVERT(CHAR(12), dbo.fn_GetDateIntime(cl.createdDate), 107)holla,
convert(char(3), dbo.fn_GetDateIntime(cl.createdDate), 0)MonthPart,
CONVERT(VARCHAR(5), dbo.fn_GetDateIntime(cl.createdDate), 114) TimePart,
CONVERT(VARCHAR(8),GETDATE(),108),

4 Answers 4

1

We can use format function -

select format(getdate(), 'dd MMM, yyyy hh:mm tt')

Output -

25 Apr, 2018 01:59 AM
Sign up to request clarification or add additional context in comments.

Comments

0

You can use convert() function:

select convert(varchar(20), date, 113) as datestring

You can also use format() function but not best for performance perspective

select format(getdate(), 'dd MMM, yyyy hh:mm tt') as datestring

Comments

0

Please try this

select convert(varchar(20),format(getdate(),'dd MMM yyyy HH:MM tt'))

Comments

0

We can achieve this by two methods CONVERT and FORMAT below is example of both. I hope this will help you...

1st way

select CONVERT(varchar,getdate(),100) as [Date Time String]
 --100 is datetime default sql format 'mon dd yyyy hh:miAM/PM'

Output -

Apr 25 2018  1:23PM

Second way

    select FORMAT(getdate(), 'dd MMM, yyyy hh:mm tt') as [Date Time String]
     -- In first parameter we have to pass date 
     -- In second parameter we need to pass date forma in string

Output -

25 Apr, 2018 01:59 AM

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.