Link to home
Create AccountLog in
Avatar of Brogrim
BrogrimFlag for Ireland

asked on

Convert Date Function

I have a table that is varchar but always starts with 2013-01-01 00:00:00 so I want to convert the varchar to a date

I ma trying to use the

select convert(IssueDate, (101)) from tblpermit

any suggestions? am i even using the correct function
Avatar of EvilPostIt
EvilPostIt
Flag of United Kingdom of Great Britain and Northern Ireland image

As long as thats 'YYYY-MM-DD HH:MM:SS' the below should work fine.

SELECT CONVERT(DATETIME,'2013-01-01 00:00:00')

Open in new window

Avatar of didnthaveaname
didnthaveaname

You aren't telling it what you want to convert to. ie:

select convert( date, IssueDate, 101 ) as convertedIssueDate from tblpermit;

Open in new window


Edit: You may have to play with this a bit, since I assumed you were trying to convert the value of what's in the IssueDate column, but after seeing EvilPostIt's take, i see it was kind of up in the air. (and 101's mm/dd/yyyy =)
select convert(varchar, IssueDate, 101) from tblpermit
There would be no difference between using the column name or the string. If the month is the other way round you may have to set the language.
Avatar of Brogrim

ASKER

select convert(varchar, IssueDate, 101) from tblpermit

returned

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar, PermitIssueDate, 101) from tblpermit' at line 1
Avatar of Brogrim

ASKER

getting the same error for all suggestions
So your using mySQL not SQL Server then...
Avatar of Brogrim

ASKER

should have mentioned that, apoligies.

MySQL
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Brogrim

ASKER

Thank you