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

DateDiff will not return anything?

anoble1
245 128KB
Hi guys,
I am trying to return the number of days from a start date and an End Date. my data source has the format yyyymmdd or 20190101. I get a #Error when I run the query.
Expand|Select|Wrap|Line Numbers
  1. Expr1: DateDiff("d",[QS36F_PARTHIST]![PH_DTR],[QS36F_PURORD]![PO_DTR])
Is it because my source is in that format and won't work?
Sep 23 '20 #1
5 2533
jimatqsi
1,271 Expert 1GB
Yes, you'll have to reformat the date fields to mm/dd/yy or whatever your local format is.

Jim
Sep 23 '20 #2
cactusdata
214 Expert 128KB
The format of a date value is for display only. So, most likely, your dates are not DateTime but Text. Thus, first convert these to DateTime, then use DateDiff:

Expand|Select|Wrap|Line Numbers
  1. Expr1: DateDiff("d",CDate(Format([QS36F_PARTHIST]![PH_DTR],"@@@@\/@@\/@@")),CDate(Format([QS36F_PURORD]![PO_DTR],"@@@@\/@@\/@@")))
Sep 23 '20 #3
ADezii
8,834 Expert 8TB
You could also use the DateSerial() Function which will return a Variant (Date):
Expand|Select|Wrap|Line Numbers
  1. Dim strStart As String
  2. Dim strEnd As String
  3.  
  4. strStart = "20190101"
  5. strEnd = "20200101"
  6.  
  7. 'Will OUTPUT 365
  8. Debug.Print DateDiff("d", DateSerial(Left(strStart, 4), Mid(strStart, 5, 2), Right(strStart, 2)), _
  9.                           DateSerial(Left(strEnd, 4), Mid(strEnd, 5, 2), Right(strEnd, 2)))
Sep 23 '20 #4
twinnyfo
3,653 Expert Mod 2GB
Also, simply converting the text to the following will work:

Expand|Select|Wrap|Line Numbers
  1. strDate = Left([PH_DTR], 4) & "-" & _
  2.           Mid([PH_DTR], 5, 2) & "-" & _
  3.           Right([PH_DTR], 2)
This produces a string with the format: "2019-01-01", which is a universally recognized Date format in Access.

As mentioned by others, it is absolutely required that you transmogrify your text value into some form of recognizable "date".

Hope this hepps.
Sep 24 '20 #5
NeoPa
32,556 Expert Mod 16PB
"Is it because my source is in that format and won't work?"
Yes. Definitely.

Access does a very powerful & flexible job of converting data for you automatically between various different types. The string data you're using is not in a form that can be recognised as a date. There are many forms that Access will recognise, but that is certainly not one of them.

My advice would mirror CactusData's and be to convert your string values into actual date values in order to pass to the DateDiff() function but the alternatives, of converting it to different string values that ARE recognisable as dates, will also work perfectly well for you.

What they don't do so well is leave you with the understanding of what's going on such that you will never need to ask such a question again. That's one of the drawbacks with coding in VBA. It's very flexible and thus allows people to work with it even when they have limited understanding of why it does what it does. The more you get into it though, the more important that understanding becomes.

Take that understanding away from this question and you will surely have benefitted.
Dec 22 '20 #6

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

Similar topics

5
by: lawrence | last post by:
I've this function, which is the method of a class. I'm posting the constructor of the class down below. For some reason, when I fill out a form and hit submit, I'm not getting any values. Can...
2
by: steve.burgess | last post by:
$sql = 'SELECT `PageTitle` '; $sql .= 'FROM `Pages` '; $sql .= 'WHERE `PageID` = 1 LIMIT 0, 30'; I have run this query in MySQL control panel and it works perfectly. When I try to do it via...
5
by: keith | last post by:
This may seem simple, but I'm having a bit of trouble figuring out exactly how to do it. I'm accessing a database through an ODBC link, and I have a query that returns only jobs completed that day...
9
by: Doug | last post by:
Hi I have a method that I would like to return the value to the calling event. I have a bad example below that doesnt give me what I want. What I want is to have a my readxml mthod return the...
7
by: supertsik | last post by:
Hi After a lot of research I didn't manage to solve the following problem: I have a table called 'Autos' with fields , , 1 ¦ Mike ¦ BMW 2 ¦ Mike ¦ Ford 3 ¦ Mike ¦ Toyota 4 ¦ Nick ¦ Audi
3
by: mikerich135 | last post by:
Is it possible that any function without return type and returning value will return any value. If so, How?
2
by: hofer | last post by:
Hi, I get following warning with a python script: optparse.py:668: FutureWarning: %u/%o/%x/%X of negative int will return a signed string in Python 2.4 and up my code:
1
by: dbytes | last post by:
I have no idea what sql command will return the results I need from 1 table. example of table and values col1 col2 col3(unique values) 1 1 abc 1 1 dev 1 2 rst 1 3 ndb 1 3 mnv
2
by: Ken Jones | last post by:
Table URL_3 consist of the following 2 columns of information being Record No and URL No URL 1 http:/publishing/45/100006_f.SAL_Local.html 2 ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
0
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...
0
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
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...

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.