473,395 Members | 1,678 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.

Date Format query in Access for SQL database

Hi,

I'm currently attempting to create a query in Access 2003 on a SQL database where I'm trying to format a date column, that's currently set as YYYYMMDD, to show as DD/MM/YYYY. Using that expression I want to retrieve data for all NULL records and any older than 90 days. The current Expression reformats the date column correctly but shows all NULL values as '#Error'. Adding the criteria '<Date()-90 or Is Null' only results in a 'Data type mismatch in criteria expression' error message.

The expression command is currently scripted as 'LASTTRANS: Format(CDate(Format([LAST_TRANS],"0000-00-00")),"dd/mm/yyyy")' in the Field row of the query builder.

I've tried various Date Format commands but so far have been unsuccesful. Any help anyone can offer would be greatly received.

Thanks,
Paul.
Oct 5 '11 #1
6 4947
NeoPa
32,556 Expert Mod 16PB
You're doing some strange stuff in there to be fair Paul. Strange even disregarding any difference between SQL Server and Access. What you have would not be expected to work with a DateTime type field. Try to treat it simply as that and see what you get first :
Expand|Select|Wrap|Line Numbers
  1. LASTTRANS: Format([LAST_TRANS],"dd/mm/yyyy")
Remember though, converting the result to a string (as you do here) rather than simply formatting the Date data as a string, is very rarely a good idea or necessary. More sensible in nearly all circumstances would be simply to set the format of the field to that format string while leaving the underlying data as a Date.
Oct 5 '11 #2
Hello NeoPa,

Thank you for your response. I had tried that command but all records just come back as '#Error' unfortunately. I know, it does seem unnecessarily complicated but it's to be used as part of a quartely systems maintenance procedure, so the idea is that it can be used whenever necessary without needing to be edited. I can only imagine the error is being caused because it's not recognised as a date column, so attempting to reformat is just confusing it? Which is why I think specifying the 0000-00-00 is working for the values but is erroring on the NULLS?

Anyway, I'll keep attempting to script it as desired but I may have to concede defeat and work around it.

Thank you,
Paul.
Oct 6 '11 #3
patjones
931 Expert 512MB
I'm confused as to whether the problem exists for all records or just null-valued date fields. If it's just for null-valued date fields then it could be handled by using something like the Nz( ) function:

Expand|Select|Wrap|Line Numbers
  1. Nz(Format([LAST_TRANS],"dd/mm/yyyy"), "")

This will simply give you a zero-length string in the event that LAST_TRANS is null.

Pat
Oct 6 '11 #4
NeoPa
32,556 Expert Mod 16PB
I don't have enough info from you to determine what state the data comes across to you in so as to determine the best approach on that score, but if it's only the Null values causing a problem, and otherwise your original code works, then try :
Expand|Select|Wrap|Line Numbers
  1. LASTTRANS: Format(CDate(Format(Nz([LAST_TRANS], XXX),"0000-00-00")),"dd/mm/yyyy")
where XXX reflects what you want to be used in the case where the value is Null.
Oct 6 '11 #5
Thanks guys. It turns out that the NULL values aren't null at all, but a four blank spaces. So that's relieved some of the confusion and I'm able to work with the data and format it to be recognised as a date. The command I'm now using is 'LASTTRANS: IIf(([LAST_TRANS] Like " *"),"NULL",(CDate(Format([LAST_TRANS],"0000-00-00"))))' which appears to be working.

Thanks for your help.

Paul.
Oct 6 '11 #6
patjones
931 Expert 512MB
Yes, that information certainly changed the whole landscape of the situation. I'm happy that you found that out and were able to rectify it.
Oct 6 '11 #7

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

Similar topics

2
by: Jim H | last post by:
I'm trying to get a bunch of records based on client id and a date range. I keep getting an error when I enclose my date string in quotes in the where cleause. The error is: Microsoft JET...
1
by: somaskarthic | last post by:
Hi In postgresql database how to retrieve the date in a required format ? Is ther any method to retrieve the stored date value in mm/dd/yyyy format. I don't want to set the date format in...
3
by: Savvas Tsitouridis | last post by:
Hello I have an Access database with a date field The format that we store values is dd/mm/yyyy (greek) The problem is that i can't retreive the correct dates because the queries return only...
2
by: lvhengani | last post by:
Can anyone help me? I am running my news from an access database, but when the date is displayed (on the browser from the database) the format is mm/dd/yyyy and I would like it to be dd-Month-yyyy. I...
1
by: saddist | last post by:
Hello, In access 2003 I have date format yyyy/mm/dd, but I want it to be dd/mm/yyyy. I tried to enter dd"/"mm"/"yyyy and dd/mm/yyyy in format property, but it changes automaticly to dd/mm"/yyyy"....
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
1
by: BulbFresh | last post by:
Hi, Quick one for you, i'm importing a file which has a long date and time format, so once imported i update each date field with the correct format (dd/mm/yyyy). I wrote this in on click of a...
9
chandru8
by: chandru8 | last post by:
hi to all iam using vb6.0 can any one correct me the query which below mentioned is correct strSql = "Insert into table1 values (#" & Date & "# ,'2')" Set rs = objCon.Execute(strSql) or
5
by: Matsam | last post by:
Hello, I have an Access program with 4 forms. In the load event of the main form, I need to set the system date format to British. Can anyone please give the code for setting the system date...
9
by: M3L155A | last post by:
I need to convert dates like this "82009" (20th Aug 09) into a proper date format. Any tips would be appreciated. Thanks
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: 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
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
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...

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.