473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Update a portion of a date formatted field with an Update query

Hi There,

I'm attempting to update a short date formatted field with a consistent year without changing the Month or Day. Below is what I have so far, when trying to update it however I get a Type Conversion Error and I'm at a loss... Any help would be much appreciated:

UPDATE [New Hires]
SET [New Hires].DOB = Right$([DOB],4) & "1901"
WHERE [New Hires].DOB Not Like "*1901";

Thanks
GN
Apr 3 '08 #1
6 1903
nico5038
3,080 Expert 2GB
Hi There,

I'm attempting to update a short date formatted field with a consistent year without changing the Month or Day. Below is what I have so far, when trying to update it however I get a Type Conversion Error and I'm at a loss... Any help would be much appreciated:

UPDATE [New Hires]
SET [New Hires].DOB = Right$([DOB],4) & "1901"
WHERE [New Hires].DOB Not Like "*1901";

Thanks
GN
Hi GN,

When your field is a real date field, the short date format is "built in" and what you see is not what you get. Access will have stored a relative daynumber and will show a "full" date when you change the format of the field.
When you entered the date Access will use a so-called "breakyear" to add the century and by default the range "00" to "39" is used for the 20th century and "40" to "99" for the 19th century.

Nic;o)
Apr 3 '08 #2
Hi GN,

When your field is a real date field, the short date format is "built in" and what you see is not what you get. Access will have stored a relative daynumber and will show a "full" date when you change the format of the field.
When you entered the date Access will use a so-called "breakyear" to add the century and by default the range "00" to "39" is used for the 20th century and "40" to "99" for the 19th century.

Nic;o)
Hi Nico,

Thanks for the reply. Could you possibly dumb that down one more level, or point me in a direction to accomplish what I'm trying to do?

Thanks again
GN
Apr 4 '08 #3
nico5038
3,080 Expert 2GB
Hi Nico,

Thanks for the reply. Could you possibly dumb that down one more level, or point me in a direction to accomplish what I'm trying to do?

Thanks again
GN
Hi GN,

First you need to tell me the datatype of the DOB field in the table :-)

Nic;o)
Apr 4 '08 #4
Hi GN,

First you need to tell me the datatype of the DOB field in the table :-)

Nic;o)
Hi Nico,

The datatype for the field is Date/Time formated to Short Date.

Thanks again,
GN
Apr 7 '08 #5
Hi GN,

First you need to tell me the datatype of the DOB field in the table :-)

Nic;o)
So, I'm a moron. I was going in the wrong direction. The follow works for the most part, still having some difficulty however.

UPDATE [New Hires] SET [New Hires].DOB = left$([New Hires].DOB,6) & "1901"
WHERE [New Hires].DOB Not Like "*1901";

I've reformatted the field to 'MM/DD/YYYY' so the date is consistently 10 characters. It replaces most of the non-1901 dates. But I'm still getting a data type conversion error for some. Not sure why, will investigate further and come back if I can't figure it out.

Thanks again for your time.
Cheers,
GN
Apr 7 '08 #6
nico5038
3,080 Expert 2GB
To manipulate the 1900's into 2000's you can use the Dateserial() function, syntax:
Dateserial("Year","Month","Day")
Sample:
Expand|Select|Wrap|Line Numbers
  1. UPDATE tblX
  2. set DOB = (Year(DOB)+1000,Month(DOB0,Day(DOB))
  3. Where Year(DOB) < 1939
  4.  
Nic;o)
Apr 7 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: vnl | last post by:
I'm trying to run a SQL query but can't find any records when trying to select a certain date. Here's the sql: SELECT field 1, field2, date_and_time, FROM table1 WHERE date_and_time =...
3
by: Ken Bush | last post by:
How can I write an update query that removes part of a field? Like if I have a field with values such as 8/3/68 (a birthday obviously) and I need to put values in a new column but I need...
0
by: Galina | last post by:
Hello My form is based on a query returning rows of a table. Practically, it is based on a table, so simple the query is. A field on the form is formatted as short time. The column in the table,...
3
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field...
10
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
2
by: Andy | last post by:
Hello, I have a question regarding how to format a date in VB so that I can call it from a query and get results. I'm calling functions in the query because that was the only way I found I could...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
8
by: kevcar40 | last post by:
Hi I have a excel worksheet that contains a lot of data one on the columns is the date(formatted as short date "dd/mm/yyyy) i import this worksheet into access as a table the date field is...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...

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.