How can I manage to have an auto-insert timestamp value in my table in SQL-Server? - sql-server-2008-r2

Im working on a project. My project contains a c# program and an attached database. I need to have a column to record the time, when data is inserted into my table.
My goal is to be able to report my data in different time intervals.
what I have already tried: I have included a timestamp column in my table. I thought adding a timestamp column will automaticly do the job for me. but its not recording time by itself I guess I have to enter time to it from a source.
I have searched my problem in google but there was not any how-to question. all questions were about the differences between time data types.

The best way is have a column with nvarchar(15) type and set it to
DateTime.Now.ToString();
in c# .
So, you can make strings you want with the date time like : yyyy/MM/dd or MM/yyyy/dd
maybe this url will help you :
https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tostring?view=netframework-4.7.2

I had to either use CURRENT_TIMESTAMP
Microsoft suggestion for having a Timestamp
which actually I didn't use it myself in my project.
What I did do was to have a label and a timer in my C# program. I would trigger the timer with a click on a button and stop it somewhere in my program and store the time value in a variable (let's call it Timevariable). Then when I'm entering other information in my database, I would use that variable to store the time which I chose it to be a timestamp in my database with the following code:
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand("AddTime", sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.AddWithValue("#otherInformation",source of that Information);
sqlcmd.Parameters.AddWithValue("#QTimeStamp", Timevariable);
sqlcon.Open();
I'm using a stored procedure here.

Related

Setting toDate function as arrival time Anylogic

I'm already struggling for days to use dates from excel in a proper way in anylogic..
I've created a database in where the date is formulated as integers in different columns since otherwise excel is messing up the dates (for example year=2021 , month=12 day=5 hour=6 minute=44 second=0 stands for 2021/12/5 6:44:00)
Now I know this can be converted to a date by the function toDate(year, month, day, hour, minutes seconds). But how can I use this integers to create agent with specific parameters from the database in a source and add to a custom population?
The most simple way is to add a column where the function toDate(......) is added in the database but I do not know how to do this (see picture if it is unclear). Or are there other solutions?
One way: use Dynamic Events.
Create one and in the action code, write mySource.inject(1)
In Main, on startup, load all dbase rows and create a DE for each row, below assuming it is only with an hour-column:
(Use the database query wizard to adjust your query).
In your source object, set it to "call of inject() function"
This will work, but it is quite cumbersome, as you can see. Much easier if you get your Excel right and just import the date column clean and well so you can use the Source option "arrival table in database" directly. I know you need regular arrivals, so maybe code that up in Excel to give you these on specific dates...

How to filter data based on a time parameter in Access?

I have a query from another thread which goes through a list of different events and pulls out the most recent event and puts it into a list. The code I'm using is:
SELECT Cleaning1, Max(Date1) AS most_recent
FROM CleaningLog
GROUP BY Cleaning1;
Cleaning1 is the column that has the different cleanings, and Date1 is the column that has the date the cleaning occurred, and CleaningLog is the name of the table. I currently have a macro in Access which is an OpenQuery, query. I am having it open the above query, and then having it view as a data sheet and it's in edit mode.
What I am stuck on, is getting a subsequent macro/query/vba code to take the datasheet the query produces and going through each item and determining if they're over due to be cleaned. I tried having a Make Table query, but the problem is, there is no user friendly way to refresh that table without having to delete it (I am having unskilled workers use this Access sheet).
I am wondering if there's a way to look at the most recent cleaning's date, what the query produces, and filter the dates out that are over due for a cleaning, specified by a parameter. I have been looking at this webpage to start playing with the notation, but I haven't been able to come up with much that is useful.
https://support.office.com/en-us/article/Examples-of-query-criteria-3197228C-8684-4552-AC03-ABA746FB29D8
Another problem that I am encountering is that each cleaning doesn't have the same time frame in which is needs to be cleaned.
Thank you in advance for any help!!
You should just be able to modify the query above to show entries with a max date lower than they should be. Below shows entries that haven't been cleaned in 30 days, for instance.
SELECT Cleaning1, Max(Date1) AS most_recent
FROM CleaningLog
GROUP BY Cleaning1
HAVING Max(Date1) < Now() - 30;

create table that has a date item in sqlite3 database in python

I'm making a database for a website and it needs to take the users input of a date but I think I can do that bit. The part I'm struggling to do is create a table with the date item. What do I need to tell it to do when creating the table I've gotcreate table Results (GameID integer,Date ???????, primary key(GameID)
I just need to to know what I set date to as its not an integer real or text.
I'm using python 3.2
SQLite does not have a built-in date type.
SQLite can store dates as a string or a number.

Filemaker Pro 11 Script - Add fields dynamically?

So we use FMP11 to do inventory management. I do price updates to our products 3 times a week and it would be nice to store our past cost values into a separate table for historical pricing. I know how I would go about doing most of it, but is it possible to create a new field that is labeled as today's date on the fly? So my headers would be labeled with that days date and the old pricing value from my other fields would be inserted.
It is a bad idea to create new fields for the purpose you're describing. Create additional records instead, and do your report going from top to bottom instead of left to right.
That said, if you want to do it, you can using FileMaker Server Advanced with JDBC and the ALTER TABLE command.
Create an new table (e.g. ArchivePricing) to hold the values you want to reference at a later date (e.g. ChangeDate, Price, Item, ItemID, etc.).
Create a new field in the current table called z|newprice - use this to type in your new pricing (you might do this on a list layout so you can easily change a bunch of prices).
Create a button that triggers a script that:
creates a new record in the new ArchivePricing table and inserts the ItemID (thus creating a link to the original table) - this can be done using script parameters or setting a variable)... the script continues.
uses the "set field" script step to insert info to this new record in the ArchivePricing table.
uses the Get (CurrentDate) function to insert the date into the ChangeDate field (thus capturing the date the change was made).
Before the script finishes be sure to use "set field" back in the original table to move the value in z|newprice field into your normal Price field. Do this at the end of the script and then commit record.

Crystal Reports - Select Current YYMM

I'm trying to create a Crystal Report that reads data from an access table. I have a particular field in the access table called REPT_YYMM. This is basically a run data field, so each month when a program is run it populates the current year/month in the field before exporting to access, so there is a way to do month to month comparisons. For the report I'm working on I just want to display the data along with the current REPT_YYMM field when the data is refreshed on a monthly basis. Is there a way to do this in a formula. I'm not familiar enough with date type functions to know where to start.
Any guidance or suggestions are appreciated!
Your question isn't very clear but if i understood correct you just need to filter the data where field REPT_YYMM = YYMM.
Goto selection formulas, record and enter:
{table.REPT_YYMM} = cStr(currentdate,'yyMM');