i am using the following expression to format a date in an msaccess query prior to exporting the data
Expr1: Right$([order details]![requested delivery date],4)+Mid$([order details]![requested delivery date],4,2)+Mid$([order details]![requested delivery date],1,2)
this picks up a general date from my table order details, (eg. 11/9/2012) and turns it into 20120911 or at least thats what i want it to do
unfortunately i an getting the output as 20129/11, which is a corruption i can not use
you can see that the 09 has been changed magically to 9/ and i dont understand how and why
can someone please advise what the correct expression should be, or if any change to the underlying data table is required.
i am using a general date format in the table –
this expression worked fine before but has now started to give me a problem since splitting the database and using attatched tables – msaccess version is 2003
any advice will be appreciated
thanks
It’s a very bad idea to manipulate dates from strings.
For one, you have to deal with variation in the position of the month, such as “1/1/2012” and “10/10/2012”.
Then you have to deal with the fact that the string returned by Access is highly dependent on the format specified for the column, and that format changes depending on the regional settings of the client.
Additionally, Access understands and may return dates in US-format:
m/d/yyyy.To solve your issues, explicitly use the date and formatting functions provided by SQL and Access to manipulate dates.
In your case, I think you just need the
Format()function:Will return
20120911if your[requested delivery date]is 11SEP2012.If your
[requested delivery date]is defined as a string instead, make sure it contains valid dates, and convert it to a proper date, usingCDate():If this column is set to allow Null values, you will need to test that:
Have a look at the following articles for more information on date manipulation: