473,480 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

HowTo Update Date Field

Could someone help me with the most efficient way to update a date field. I
have a field with Date and Time in it but I want to update it with only the
Date and strip off the time. Any ideas for the shortest way to do this?
Jul 20 '05 #1
4 78977
DATETIME / SMALLDATETIME columns always contain both date and time. Use the
format 'YYYYMMDD' (no spaces) to define the date value. The time will
default to midnight. For example:

UPDATE YourTable
SET date_col = '20041122'
WHERE ...

You can format the value without the time for display and printing purposes.
Usually your application program is the best place to format the date.

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2
My problem is that I have the date/time already in the table and I need to
do all the formating within the SQL statement.

"David Portas" <RE****************************@acm.org> wrote in message
news:Jv********************@giganews.com...
DATETIME / SMALLDATETIME columns always contain both date and time. Use
the format 'YYYYMMDD' (no spaces) to define the date value. The time will
default to midnight. For example:

UPDATE YourTable
SET date_col = '20041122'
WHERE ...

You can format the value without the time for display and printing
purposes. Usually your application program is the best place to format the
date.

--
David Portas
SQL Server MVP
--

Jul 20 '05 #3
fwiest (fr**@fredwiest.com) writes:
My problem is that I have the date/time already in the table and I need to
do all the formating within the SQL statement.


Your question was about updating. And you cannot change the format of a
datetime column in SQL Server. A datetime value is always stored in a
binary form.

You can do some formattinig when you select the data. For instance to
get the date portion only:

SELECT convert(char(8), datetimecol, 112) FROM tbl
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4
Thanks exactly what I was looking for. Thank you very much.
"Erland Sommarskog" <es****@sommarskog.se> wrote in message
news:Xn**********************@127.0.0.1...
fwiest (fr**@fredwiest.com) writes:
My problem is that I have the date/time already in the table and I need
to
do all the formating within the SQL statement.


Your question was about updating. And you cannot change the format of a
datetime column in SQL Server. A datetime value is always stored in a
binary form.

You can do some formattinig when you select the data. For instance to
get the date portion only:

SELECT convert(char(8), datetimecol, 112) FROM tbl
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
370
by: rkbnair | last post by:
In order to update the date properly, should I add anything before and after the variable dte_send_again? str_update_command = "UPDATE web_tbl_emails SET dte_resend= " + dte_send_again +",...
1
2796
by: Liz Malcolm | last post by:
Hello and TIA. I have a DE form with an option group that if daily is selected todays date is used for start and end date, if weekly is selected Monday - Friday is used. I am trying to add a...
1
1830
by: Graham Feeley | last post by:
I have a date field named rcdate it is a general date eg: 12/08/2006 3:30:00 PM 12/08/2006 3:00:00 PM I used to update another empty field named rdate with the with using in a update query "...
1
1975
by: kunal0101 | last post by:
Hi, I am a new user to access and am building a database to capture the rotation dates for employees. There is a table called "Rotation schedule" which contains "name", "Duration (in weeks) and...
0
2353
by: Sambhav | last post by:
Hi I am using MS sql right now I m felling up the data into the database using a software called DTM data generator so my problem is I have filled all the dates in 4 different columnsin a single...
4
4581
by: EOHS | last post by:
I use Access 2002. I created a form that updates when a patient gets a Flu Vaccine. I would like to simply check a checkbox and the form should take todays date and store it in the field FLUDATE...
22
3564
by: tonialbrown | last post by:
I have an Sql update statement that I am using that updates the data from a record chosen by the user from a list box lstDelFrom. This is working for all the text fields & updates fine. Once I add...
4
2003
by: Dr Al | last post by:
I have a project which requires the batch import of customer contact information, print mailing labels for those customers who have their date of first letter field in the database set to null, and...
4
3594
by: bluemoon9 | last post by:
I would like to make my "MODDATE" field to be updated to the current date when user edit record by "Click on Save" button Here is my code for the "Save" button: Private sub Save Click() MsgBox...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6732
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.