473,386 Members | 1,753 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,386 software developers and data experts.

Datediff where date format is yyyymmdd

HELP!!....I need to calculate the numer of days elapsed between two field.
But, the date format is YYYYMMDD. How can i accomplsh this?

--
Dontell Trevell

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200701/1

Jan 31 '07 #1
10 16934
DontellTrevell wrote:
>HELP!!....I need to calculate the numer of days elapsed between two date fields.
But, the date format is YYYYMMDD. How can i accomplsh this?
--
Dontell Trevell

Message posted via http://www.accessmonster.com

Jan 31 '07 #2
On Wed, 31 Jan 2007 23:09:53 GMT, DontellTrevell via AccessMonster.com
wrote:
HELP!!....I need to calculate the numer of days elapsed between two field.
But, the date format is YYYYMMDD. How can i accomplsh this?
What are the 2 fields datatypes?
If both are Date datatypes, then simply subtract one from the other.
The Format of the field is irrelevant.
[DaysDifference] = [Date2] - [Date1]

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Feb 1 '07 #3
fredg wrote:
>HELP!!....I need to calculate the numer of days elapsed between two field.
But, the date format is YYYYMMDD. How can i accomplsh this?

What are the 2 fields datatypes?
If both are Date datatypes, then simply subtract one from the other.
The Format of the field is irrelevant.
[DaysDifference] = [Date2] - [Date1]

Thank You very much!!!! I did'nt know it was that simple.....DontellTrevell

--
Dontell Trevell

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200702/1

Feb 1 '07 #4
Help Again!! It works for most but here is an instance when it does'nt work:

20060929 - 20061004 = 75 instead of 5 days. Why is it calculating 75 days
intead of 5 days?

fredg wrote:
>HELP!!....I need to calculate the numer of days elapsed between two field.
But, the date format is YYYYMMDD. How can i accomplsh this?

What are the 2 fields datatypes?
If both are Date datatypes, then simply subtract one from the other.
The Format of the field is irrelevant.
[DaysDifference] = [Date2] - [Date1]
--
Dontell Trevell

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200702/1

Feb 1 '07 #5
DontellTrevell via AccessMonster.com wrote:
Help Again!! It works for most but here is an instance when it
does'nt work:

20060929 - 20061004 = 75 instead of 5 days. Why is it calculating 75
days intead of 5 days?
Because you don't have dates, you have numbers. Quoting Fred's original
response...

"If both are Date datatypes, then simply subtract one from the other."

If your data type are not dates then simply subtracting them will not work.
You will need to convert them to dates first...

DateValue(Format([YourField],"0000-00-00"))

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

Feb 1 '07 #6
Where does the formula below go? DateValue(Format([YourField],"0000-00-00"))
Rick Brandt wrote:
>Help Again!! It works for most but here is an instance when it
does'nt work:

20060929 - 20061004 = 75 instead of 5 days. Why is it calculating 75
days intead of 5 days?

Because you don't have dates, you have numbers. Quoting Fred's original
response...

"If both are Date datatypes, then simply subtract one from the other."

If your data type are not dates then simply subtracting them will not work.
You will need to convert them to dates first...

DateValue(Format([YourField],"0000-00-00"))
--
Dontell Trevell

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200702/1

Feb 1 '07 #7
On Thu, 01 Feb 2007 17:18:16 GMT, DontellTrevell via AccessMonster.com
wrote:
Help Again!! It works for most but here is an instance when it does'nt work:

20060929 - 20061004 = 75 instead of 5 days. Why is it calculating 75 days
intead of 5 days?

fredg wrote:
>>HELP!!....I need to calculate the numer of days elapsed between two field.
But, the date format is YYYYMMDD. How can i accomplsh this?

What are the 2 fields datatypes?
If both are Date datatypes, then simply subtract one from the other.
The Format of the field is irrelevant.
[DaysDifference] = [Date2] - [Date1]
Your computer is working correctly.
As numbers, 20061004 - 20060929 = 75

Remember this part of my reply?
>>What are the 2 fields datatypes?
If both are Date datatypes, then simply subtract one from the other.
As a Date datatype, 10/04/2006 is stored as 38994 .
As a Date datatype, 9/29/2006 is stored as 38989.

38994 - 38989 = 5

If the values are a Date datatype, the actual format of the value is
not important. The field can display, as a date, 38994 formatted as
10/04/2006 or 04/10/2006 or 20061004 or October 4, 2006 or even simply
October, but it's value is still 38994.

If the actual datatype of the values are not date datatypes, you first
need to convert them to date datatype, then you can perform the math.

From the Access debug window...
? DateSerial(2006,10,04) - DateSerial(2006,9,29)
5

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Feb 1 '07 #8
DontellTrevell via AccessMonster.com wrote:
Where does the formula below go?
DateValue(Format([YourField],"0000-00-00"))
Wherever you are doing your subtraction.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Feb 1 '07 #9
Wow!!...Let me start over......Here's what I'm tring to do: I have 2 date
fields [StartDate] & [EndDate] from an ODBC table that are TEXT fields. How
can I simply convert from text to serial so I can perform the calculation.
Can I use the query criteria? If so, what do I type in the query criteria?

Rick Brandt wrote:
>Where does the formula below go?
DateValue(Format([YourField],"0000-00-00"))

Wherever you are doing your subtraction.
--
Dontell Trevell

Message posted via http://www.accessmonster.com

Feb 2 '07 #10
DontellTrevell via AccessMonster.com wrote:
Wow!!...Let me start over......Here's what I'm tring to do: I have 2
date fields [StartDate] & [EndDate] from an ODBC table that are TEXT
fields. How can I simply convert from text to serial so I can
perform the calculation. Can I use the query criteria? If so, what
do I type in the query criteria?
So what you have are Text fields that happen to contain only digits that
happen to represent dates. (even sounds silly doesn't it?)

If these are text then you are going to need to go through multiple
conversions or split the string up and use one conversion. The DateValue()
function needs a date or a string that looks like a date. If we insert
dashes into your string that will give us a good string that looks like a
date, but to insert the dashes with the Format() function we first have to
convert the string to a number and then the Format function will give that
back to us as a String again.

DateValue(Format(CLng([StartDate]),"0000-00-00"))

You might get away with omitting the CLng() function above but Access will
still be coercing the string to a number in the background so it is better
practice to just explicitly do it yourself.

You could also split the string up and feed that to the DateValue() function
like this...

DateValue(Left([StartDate],4) & "-" & Mid([StartDate],5,2) & "-" &
Right([StartDate],2))

While that is longer it involves fewer data type conversions. I have no
idea if you would notice a speed difference. So using the first example
your date difference would be found with...

DateValue(Format(CLng([EndDate]),"0000-00-00")) -
DateValue(Format(CLng([StartDate]),"0000-00-00"))

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Feb 2 '07 #11

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

Similar topics

15
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
6
by: Dario Di Bella | last post by:
Hi all, we have the following urgent issue affecting our development team. Initially we had one particular workstation that failed executing queries on a DB2 database, raising an invalid date...
3
by: FlexCrush | last post by:
Is it possible to convert a date format ("yyyymmdd") to ("mm/dd/yy")? Thank you in advance
20
by: andreas | last post by:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors. How can I change for a while in the...
2
by: pcouas | last post by:
Hi, I need to create an XSD file for XML document In mys XML document i could have various date format YYYYMMDD, YYMMDD, DDMMYY, DDMMYYYY I know theses formats before creating xsd file, but i...
2
by: thewilldog | last post by:
Hello, I've reviewed the archives here to address the issue, but I'm still running into problems. I've got a table field populated with the record date in text "YYYYMMDD" To convert it into a...
3
by: YSpa | last post by:
Hi, I'm using SQL-Server Express 2005 on Windows XP Prof. and after working properly for some time my asp.net application suddenly gave the error that my DateFormat wasn't accepted while using...
4
by: naaniibabu | last post by:
I have one number i want to convert in to a date format the size of the value is =8 Char 20091212 i ant to conver it in to a date format my sysyem doent understand wether its adate or not its...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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
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,...

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.