Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! I'm using MySQL 2005.
I'm just starting to learn it so I need some help.
Is there a way to store dates only in a datetime column in sql?
When i enter a date, it automatically puts a default time beside it. So i was wondering if there was a way to store dates only.
Posted
Comments
dan!sh 13-May-14 1:41am    
Are you using MySQL or MS SQL?
charliedev 13-May-14 2:10am    
MS SQL Server
saisrid 13-May-14 1:42am    
try this,

In sqlserver for date give datatype as nvarchar(10)


In the code as

DateTime.Now.ToString("dd/MM/yyyy")
phil.o 13-May-14 3:51am    
Advising someone to store a datetime as a string? I would vote 1 if I could. Sorry but encouraging bad practices is not the primary goal of this forum.
RahulMGunjal 13-May-14 1:58am    
In SQL Server, it stores as datetime only

there is no type called Date in SQL server 2005, you need to use datetime type

check Date and Time Data Types and Functions - SQL Server (2000, 2005, 2008, 2008 R2, 2012)[^]

You can store date as string but it is not recommended, read this[^] and Is it a good practise to store date as stirng?[^]
 
Share this answer
 
v4
Comments
saisrid 13-May-14 2:05am    
The date I have specified is the column name for that we should give datatype as
nvarchar(10).I did not specify the date as a datatype .Plz read the content carefully.
DamithSL 13-May-14 2:09am    
what! I haven't answer to your question. what are you talking about?
Almost all database store date and time as DateTime. The simplicity in this approach is that it supports both date and time formats. For example if you only want to save the date you simply eliminate the time in the date and store it. For example if you like to store 01-Jun-2014 10:23:14 am you simply truncate it to 01-Jun-2014 00:00:00 am and save it as date time. Additionally if you like to store a date for example 10-Jun-2014 sql server will store it as 10-Jun-2014 00:00:00

Therefore no additional efforts is required to manipulate time. Please Cast and Convert functions for truncation
 
Share this answer
 
Comments
charliedev 13-May-14 2:41am    
oh, so i can't really have a datetime column that shows the date only.

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