473,854 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
+ 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 79026
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******** ************@gi ganews.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****@sommarsk og.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****@sommars kog.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****@sommarsk og.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 +", str_mail_to='"+"ccc" + "' WHERE lng_id = "+ lng_id.ToString ();
1
2811
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 manual date selection to clear the start and end date to allow the end user input other days. I have taken into account our financial 1st and last day of the month. I was able to break the option group into a select case, but I cannot get the date...
1
1846
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 " Left(Ratings!RCDate,10)" This now does not work for some reason gives me the error "undefined function in left function"
1
1998
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 "rotation date" fields. Each employee will have many records in this table corresponding to each rotation. What i need to do is that when a user enters the duration in weeks for a particular MA, i need to auto calculate the next rotation date...
0
2485
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 table randomly Now they all hav restrictions like (date A < date B) and same way (date B<date C) and (date B <date D) so what I am doing is first I am randomly assigning the dates between 2003 till 2007 then using Sql statment like update tablename...
4
4614
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 from table FLU. I have the other fields from the table FLU on the form and they update properly. FLUDATE is defined as a "shortdate". On the form, the ControlSource for the Checkbox is FLUDATE. In the "After Update" section - I typed: ...
22
3615
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 in one of the fields that is a Date field I cannot get the update to work. ie) this line ". = #" & Nz(rst.Fields(9).Value, "") & "#," & _ Could someone assist me with the correct syntax to use. I also need to consider that the field may be...
4
2042
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 update the date of first letter field with the date the mailing labels are printed. I already have a query which checks the date of first letter field, and returns those customers whose date of first letter field is null. How do I setup to...
4
3615
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 "Record has been updated successfully!", vbInformation, "RECORD HAS BEEN UPDATED!" Me.MODDATE.Value = Date DoCmd.Close acForm, "frmReview", acSaveYes End Sub In the tblReview, I have a field call "MODDATE", and I set this field to have a...
0
9901
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9751
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11027
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10682
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10761
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10371
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9513
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4159
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.