MS Access: importing Date "3 Dec 2020" into 'date/time' column gives error, how do I get it to recognise it's a date? - date

I'm very, very new to databases, and trying to collect data from online shops we use. Apologies if this is a repeat question, I couldn't find existing questions that matched my problem for the life of me.
One of the sites we use gives dates in the format "3 Dec 2020" when I download a .csv file.
If I try to import into a table whose 'Date' column is formatted "Date/Time", it throws an error and won't log the date information at all.
If I import the .csv data when the Access 'Date' column is formatted as a "Short Text" column, and then after it's imported, change it back to "Date" format, it's fine and reformats those dates to 3/12/2020 format.
Putting in a space (" "), or "-", as the date delimiter when looking at the advanced import specification doesn't seem to work to get it to log the dates in a column formatted "Date/Time"
I tried looking into Masks but was quite confused by it
Could someone help me figure out how to get it directly into a 'Date/Time' column instead of me having to set it as 'short text' and back to 'date/time' again?
Thanks ><

Don't import the file but link it.
Then, use the linked table as source in a simple select query where you modify and filter the data as needed. For example, both CDate and DateValue will convert a text date to a true DateTime value:
TextDate = "3 Dec 2020"
TrueDate = DateValue(TextDate)
' TrueDate -> 2020-12-03
Finally, run an append query using the select query as source to append the data to your table.

Related

Date Time and Conversion Functions not available in MS Access 365 at Table Design Time

I'm trying to simply convert a text field into a datetime value in MS Access 365. This should be simple. However I don't seem to have access to functions like Date(), DateValue().
I want something where I can just pass some text in and it converts to a datetime type. My data looks like this:
I used the formula: I used this formula to get this: Left$([DateText],InStr(1,[DateText]," - "))
to remove the time from the DateText field.
Now I want to add a new field which is a date/time type using the data in the DateTextWithTimeRemoved field.
The table design view (also showing the conversion functions available) is like this:
And the date functions are these:
And so, from years ago I remember using functions like CDate() or Date() or DateValue() or what have you, but they're just not there. Do I have to install something to get these functions?
Assuming you want to keep the same Table fields shown in your question:
Make a backup of your current table.
Change the Data Type of the DateThatIsAnActualDate field to Date/Time and DateTextWithTimeRemoved to Short Text.
Create an an Update Query. (Create -> Query Design -> select Update under Query Type.)
Add your Table (members)
Field: DateTextWithTimeRemoved
Table: members
Update To:
Left([DateText],InStr(1,[DateText]," -"))
next column
Field: DateThatIsAnActualDate
Table: members
Update To:
Format(DateValue(Left([DateText],(InStr(1,[DateText]," -")))),"dd/mm/yyyy")
Click Run !
Click Yes to confirm.
All done. Check the records in the members table.
First, forget about the calculated fields. Use queries, that's what they are for. Tables are for data.
Second, the Expression Builder is hopeless. I have never found it useful.
Next, all you need for an easy conversion to true date values, is to remove the dash.
TextDate = "10 Dec 2020 - 16:52"
? Replace(TextDate, "-", "")
10 Dec 2020 16:52
This can be converted like this:
' Date only:
? DateValue(Replace(TextDate, "-", ""))
2020-12-10
' Date and time:
? CDate(Replace(TextDate, "-", ""))
2020-12-10 16:52
Now, your query could look this this:
Select
ID,
Username,
DateValue(Replace(TextDate, "-", "")) As TrueDate,
CDate(Replace(TextDate, "-", "")) As TrueDateTime
From
Members
Note, that date/time values carry no format. Apply this for display only, so adjust the Format property where needed (the forms/reports where you view the data), if the default format (that of your Windows settings) doesn't fit.
Format: dd/mm/yyyy
The default is:
Format: Short Date

Google Sheets - Date Format Display Issues

I'm currently building dashboards in Google Sheets and have run into a consistent issue with dates being displayed as a number opposed to a date format. EX: 43626 opposed to 6/11/19.
This data is being pulled from form sheet into a database, then queried into the dashboard spreadsheet where it is coming through as a number sequence opposed to readable date format. Currently have tried to use the DATEVALUE to reformat, as well as attempted to reformat the cell into a date format in both dashboard and database locations, with no luck.
//What I've tried
=TargetCell
43626
=DATEVALUE(TargetCell)
43626
=TargetCell //Reformatted as any Date format
43626
I was expecting the following
=DATEVALUE(TargetCell)
6/11/19
OR:
=TargetCell //Reformatted as any Date format
6/11/19
you got it wrong... function DATEVALUE creates 43626 from 6/11/2019
if you want to reverse it you need to use either:
internal custom date formatting (does not work all the times)
TEXT formula like: =TEXT(43626, "m/d/yy")
QUERY parameter format like: =QUERY(A:B, "format A 'm/d/yy'", 0)
or QUERY parameter toDate like: =QUERY(A:B, "toDate(A)", 0)
https://developers.google.com/chart/interactive/docs/querylanguage#top_of_page

Data stored as DD/MM/YYYY in table, but querying in DD/MM/YYYY doesn't work for all dates MS Access 2016

There are probably many questions that are asking about date formats, but I haven't found anything like this.
I have a table, called t_birthday. t_birthday has a field called "DayOfMonth" which currently stores the data in a dd/mm/yyyy format. Lets say the record I have has the Date of 01/12/2016 (Dec 1, 2016).
Now, if I create a query using the "Query Design" option in the Create tab, I select my table t_birthday. For the field option, I select DayOfMonth. In the criteria option, I put =#01/12/2016#. When I click Run, it queries the database and returns the record with that date successfully.
However.. If I check the SQL generated from this Query Design, it is this:
SELECT t_birthday.DayOfMonth
FROM t_birthday
WHERE (((t_birthday.DayOfMonth)=#12/1/2016#));
If I try copy and pasting the DayOfMonth value from the table into that query, it wouldn't work. Notice how the format in the query is mm/dd/yyyy, but in my table it's still dd/mm/yyyy. I never touched any of the date formatting options in my table, or even on my computer. When I actually create this record using a form, I have a date picker which is in the form of dd/mm/yyyy as well.
Questions:
In the query design, when I specify criteria in dd/mm/yyyy, why does it generate sql in the form of mm/dd/yyyy?
I can only query dates using dd/mm/yyyy format if the day number (1-31) is 13 or above, OR if the month value and the day value are the same (October 17, Jan 1, March 3, November 11, December 12, etc). mm/dd/yyyy still works for those dates previously mentioned. I can't query dates like November 7th, Feb 3rd, August 4th, etc using dd/mm/yyyy though. How do I get around this problem? I store the dates, and I use the values directly from the table as conditionals in my queries. I shouldn't have to alter my date value in order to use them.
Why can I write an SQL statement for dates with the day number above 13 in dd/mm/yyyy format or mm/dd/yyyy format? E.g., the WHERE clause can look like: WHERE DayOfMonth=#13/06/2018 or WHERE DayOfMonth=#06/13/2018 and it still returns the same record? Why does access not enforce a specific format?
EDIT:
Currently I run my query in VBA and return it into a recordset using the following:
Dim bdayRecords As RecordSet
Dim sql As String
sql = "SELECT t_birthday.DayOfMonth"
sql = sql & " FROM t_birthday"
sql = sql & " WHERE (((t_birthday.DayOfMonth)=#" & rs("DayOfMonth") & "#));"
bdayRecords = CurrentDb.OpenRecordset(sql)
Where rs in the where clause was a previous recordset with a date value stored in "DayOfMonth". The rs recordset retrieved the date value from a different table in the exact same way bdayRecords was populated.
bdayRecords won't find the records with the date values matching the criteria explained before.
Use a properly formatted string expression for the date value retrieved:
sql = sql & " WHERE t_birthday.DayOfMonth = #" & Format(rs("DayOfMonth").Value, "yyyy\/mm\/dd") & "#;"
The ISO sequence yyyy-mm-dd works everywhere, so make it a habit to use that.
SQL always uses mm/dd/yyyy. That's not dependent on how you format it.
You never actually store a date in a certain format. You display a date in a certain format. All dates in Access are stored as a double-precision floating number containing the number of days elapsed since 30-12-1899, with fractions as time. How dates are formatted has no influence whatsoever on your SQL statement
Always use either mm/dd/yyyy or yyyy-mm-dd in your SQL. VBA only takes mm/dd/yyyy.
However, Access is opportunistic when working with clearly invalid dates, such as 13/1/2018. Because no 13th month exists, it parses it as the 13th of january, even though it's not a valid date.
If you're using values from other queries, there shouldn't be any problems, since the values never get cast back and forth to strings. You only get in trouble when casting a date to a string and then back to a date, which is not something you should do in queries, ever.
To avoid casting back and forth between strings, you can either refactor your code to a single query instead of retrieving a value from a recordset and inserting that value in a string SQL statement, or use parameters, which allows you to use the date value directly in an SQL statement.
For explanations why these design choices are made, ask Microsoft, they wrote the program. This is just how it works.

Hive datatype confusion

I have a large data and in that one field be like Wed Sep 15 19:17:44 +0100 2010 and I need to insert that field in Hive.
I am getting troubled for choosing data type. I tried both timestamp and date but getting null values when loading from CSV file.
The data type is a String as it is text. If you want to convert it, I would suggest a TIMESTAMP. However you will need to do this conversion yourself while loading the data or (even better) afterwards.
To convert to a timestamp, you can use the following syntax:
CAST(FROM_UNIXTIME(UNIX_TIMESTAMP(<date_column>,'FORMAT')) as TIMESTAMP)
Your format seems complex though. My suggestion is to load it as a string and then just do a simple query on the first record until you get it working.
SELECT your_column as string_representation,
CAST(FROM_UNIXTIME(UNIX_TIMESTAMP(<date_column>,'FORMAT')) as TIMESTAMP) as timestamp_representation
FROM your_table
LIMIT 1
You can find more information on the format here: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
My advice would be to concat some substrings first and try to convert only the day, month, year part before you look at time and timezone et cetera.

IBM i (AS400/ISeries) - Adding days to date field in WRKQRY

I have a decimal date field (TDDATR) that is in the YYYYMMDD format.
I would like to create a field that is TDDATR + 30 days but I am unable to.
Using 'Define Results Field' I have tried a few things;
Simply doing this;
TDDATR + 30 DAYS
But it returned this error: Labeled duration not used correctly.
I tried using the DIGITS and SUBSTR commands to create a field in the DDMMYYYY format and then +30 days but got the same error.
Same as above but in the DD/MM/YYYY format - same error.
Using DATE(TDDATR) but all I see is +'s in the field.
Using DATE( ) on the fields created in step 2 and 3 - still get +'s
I've ran out of ideas - any help would be greatly appreciated.
Query/400 lacks a lot of the features that an SQL based interface has.
I'd urge you to consider switching to Query Manager (STRQM) which is a fully SQL based product. You can even convert Query/400 queries to Query Manager queries with the RTVQMQRY command by having the ALWQRYDFN parm set to *YES.
The other option that IBM is pushing is Web Query. Again, fully SQL based and you can convert Query/400 queries into it.
Having said that, the problem is that FLD + 30 DAYS only works when FLD is a DATE data type. Query/400 includes a DATE() function to convert non-date types into date. But it's very limited in that it only works with character fields formatted according to your job defaults. Assuming you're in the US, it'd only work with a character value of '07/01/15'.
You could do a lot of manipulation in Query/400 and end up with a result field that meets DATE()'s requirements. But a better solution would be to create an SQL view over your table and have your numeric date converted into a date data type in the view.
You can find code examples that show how to convert a numeric YYYYMMDD to a actual date data type in the view. However, I'd recommend create a user defined function (UDF) that will do the conversion for you. That will make it much easier to use in the view and to reuse in other places.
If you'd like, there's an open source package called iDate, that includes all the code required for convert to/from date data types.
Download that, install/compile it and your SQL view becomes
select ... idate(TDDATR,'*CCYMD') as TD_DATE
from myfile
The use of days is as follow
Field Expression
CURDATE_30 days(current(date)) + 30
The solution to your problem is: given the field A dec(8,0)
Field Expression
YYYYMMDD_ date(substr(digits(a),5,2)||'/'||
substr(digits(a),7,2)||'/'||
substr(digits(a),3,2))
NEXT_MONTH DAYS(YYYYMMDD_) + 30
Remember to check the date format in your job description. In the example the format is MDY or MM/DD/YY.
More info here
Based on the information here, I created the below 2 fields;
TDDIGI DIGITS(TDDATR)
TDDAT1 SUBSTR(TDDIGI,7,2)||'/'||
SUBSTR(TDDIGI,5,2)||'/'||
SUBSTR(TDDIGI,3,2)
From here I was able to create a date field;
TDDAT2 DATE(TDDAT1)
Which allowed me to perform the necessary calculations.
The format of TDDAT1 is based on your job description which can be found by;
WRKJOB
Option 2
Page down
Date format..: X
Mine was *DMY, so TDDAT1 was formatted based on this.