Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi to all,
how to write query for date format in sql,Here i already write ms access query

for date
(Format('{0}', 'dd/mm/yyyy'),
. Now same think i want to write in sql

query. and datatype is datetime in sql.
Posted

 
Share this answer
 
v3
Comments
JOTHI KUMAR Member 10918227 13-Feb-15 5:22am    
here i asked in mccess we put (Format('{0}', 'dd/mm/yyyy') like that but in sql how to put format for datetime.
Rajesh waran 13-Feb-15 5:23am    
In Sql you may try Convert().
JOTHI KUMAR Member 10918227 13-Feb-15 5:24am    
yes because in database type should be in datatime
JOTHI KUMAR Member 10918227 13-Feb-15 5:38am    
i have to write this dateformat in insert query. my database type is in datetime format
1) Supposing you mean SQL Server. You can use CONVERT[^]. From SQL Server 2012 you have FORMAT[^] also.
2) Don't do that. If you have any presentation layer above the data access layer, better do formatting there.
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 13-Feb-15 5:22am    
here i asked in mccess we put (Format('{0}', 'dd/mm/yyyy') like that but in sql how to put format for datetime.
Zoltán Zörgő 13-Feb-15 5:25am    
Not clear. Pleas specify which RDBMS you have!
JOTHI KUMAR Member 10918227 13-Feb-15 5:29am    
here i have datatype for date is DataTime in database. Now how i write query for this format in SQL .
JOTHI KUMAR Member 10918227 13-Feb-15 5:31am    
i have to write this dateformat in insert query. my database type is in datetime format
Zoltán Zörgő 13-Feb-15 7:04am    
I asked, which RDBMS you are using: MS Access, MS SQL Server, MySQL, PostgreSQL, Oracle, Firebird,....?
Date is a date, does not need to be formated!

If your sql server uses different than end-user date format, use SET DATEFORMAT[^] command.
 
Share this answer
 
Delphi
insert into table1(approvaldate)values(18-06-12 10:34:09 AM);
 
Share this answer
 
Comments
CHill60 27-Feb-15 8:29am    
Reasons for my vote of 1:
- the question is a couple of weeks old and already resolved
- your SQL is incorrect - it results in the error "Msg 102 : Incorrect syntax near '10'."
- Even if you surround your date and time with single quotes you will still get the error "Msg 242: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."
- If you changed it to insert into table1(approvaldate)values('18-JUN-12 10:34:09 AM'); then it would work but the OP would be stuck with a date of your choosing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900