MS Access; Remove Time stamp from Date\time field in all records - ms-access

Is there another way besides running an Update QUery to take 1 particular Date\Time field in my main table to "mm/dd/yyyy hh:mm:ssPM" to just "mm/dd/yyyy"?
ive seen other answer's that involve querys or VBA but I didnt know if there was a secret access command for this type of change. If not I will run a query but im always eager to know short cuts!

You can use a select query to rip the time part:
Select *, Fix([YourDateTimeField]) As DateOnly From YourTable

Related

MS Access update query not updating errors out

I have a query in Access that I started as a Select Query. I am getting the correct results and am trying to update a specific field in a table with the results. How do I do that? This is an elapsed time from when someone took possession of a room in a house to current date. The calculated field works but for some reason whenever I try to change it from select to update it errors out.
Field = Days: DateDiff("d",[entrydate],Now())
Update to=[Rates].[TotalDays]
Error=DateDiff("d",[entrydate],Now()) is not a valid name. Make sure
it does not include invalid characters or punctuation and that the
name is not too long.
Any help is greatly appreciated.

CURDATE functionality from db2 query

I'm trying to apply 'curdate()' functionality to a select statement from DB2. I'm used to MySQL but I'm still trying to get the hang of a lot of the DB2 functionality and how to essentially marry the two.
My query is complete except for one line. I'm trying to select based on a ship date, which is the column EXTD1H and I need to check it against today or curdate(). The problem is that column in DB2 is an integer format, not a date format, and I don't have the option of changing it. In prior inserts to mysql, I've been able to put it into Y-m-d format and I know I can trim the year using LEFT(EXTD1H, 4) but I have no idea how to modify my select so that I can say WHERE EXTD1H is today so that I'm only selecting records for this date.
Here's the query:
select
invnoz as ORDER,
fstatz as STATUS
from gportafl
/*where EXTD1H is curdate, hypothetically*/
AND FSTATZ <> 'S'
limit 20;
As you can see, I have a commented line where my issue is. I'm sure it's simple I just can't seem to find in the documentation exactly what I'm looking for, which is to be able to use that INT column to verify that selected records are from today.
UPDATE:
All values from the column are in YYYYMMDD format i.e.
20180202
but it should be 2018-02-02
It's best not to do operations on the columns, so the indexes are used.
You can typecast the current date to fit your data as follows:
WHERE extd1h = INTEGER(VARCHAR_FORMAT(CURRENT DATE,'YYYYMMDD'))

Selecting a period in field based on range

Thank you all in advance for any help. I'm Still very new to access and have no idea where to start to find a solution.
What I am trying to do is to auto populate a field in my table called "Period". I would like to have it use the "Activity_Date" to look into a different table that has date ranges that reference to the correct period. Based on which "Period" the "Activity_Date" falls under will return the correct "Period". I've tried using calculated data type and queries and I feel no closer to an answer than when I started.
Thanks again for your time.
I would question why you NEED to populate the field period in your table.
In short, I wouldn't bother.
The period it is in can be derrived from the activity date field that is in the same record.
So you can write select statements that calc the period for the record in your MyTable as required.
SELECT TableWithPeriods.period, MyTable.activity_date
FROM MyTable
LEFT JOIN TableWithPeriods
ON MyTable.activity_date
BETWEEN TableWithPeriods.StartDate
AND TableWithPeriods.EndDate
If you need to access the period a lot then there is an argument for keeping a period value in the MyTable in step with the TableWithPeriods.
Keeping in step could be akward though as what if someone changes one of the period 's dates?
Keeping in step might mean writing a bit of SQL to update ALL MyTable rows that wither do not have the period set or when the period is now different.
A VBA update statement will look a bit like the SELECT above.
Or
you could use database the onchange macros that respond to data being added or updated in the MyTable (and the TableWithPeriods, if users can change dates).
Anyway, there's my opinion. I would NOT copy the value over.
PS I'm not 100% sure about the SQl I gave above, this might work though
SELECT TableWithPeriods.period, MyTable.activity_date
FROM MyTable
LEFT JOIN TableWithPeriods
ON ( MyTable.activity_date >= TableWithPeriods.StartDate
AND MyTable.activity_date <= TableWithPeriods.EndDate )

Extract results updated in last 2 hours

I am trying to write a query to extract records updated in the last 2 hours in SQL Server 2008.
Could anyone help me write this?
select * from table where table.date1>=dateadd(hh,-2,getdate())
dateadd() function lets you subtract hours from getdate() letting you choose records updated past 2 hours
First, you have to design the table so you have a field where the time of the last change will be stored
Then, whenever you update a row, update the value in the 'last update' field. After that, you can use a script such as suggested by Vijaykumar
The downside of this method is that when a single record was changed more than once in the specified time period, you will be notified only about the time of the last update.
Another solution for tracking the updates is to read the database online transaction log file, but you'll need a third party tool for that

compare timestamps in mysql

I save timestamps in my database in this format 2012-04-16 08:58:55. I read a timestamp of my database and then i want to use this timestamp in another query and ask from the database to return records where the timestamp is greater equal than this timestamp. I am using the ">=" but it is not working.
I am trying this one:
$query="SELECT DISTINCT timestamp,text FROM array WHERE id='$theID' AND timestamp>='$thisTimestamp'";
What exactly does "not working" mean? It's not clear whether you want to compare datetime stamps or simply the time porition.
For the former, check this thread Mysql Compare two datetime fields, for the latter, simply use the TIME() function in your query e.g. SELECT * FROM table WHERE TIME(datetime) >= '08:58:55';
Clarify your question if you are in search of something else.
EDIT: Have you not read my first link? That is exactly what you need given the problem you have provided so far. What results are you looking for? Give an example and then give an example of how your query is performing incorrectly. Without this information, no one will be able to give you complete help!