I want a default on a column(smalldatetime data type) where the time value is current time + 6hrs and updates continuously - sql-server-express

I want a default on a column(smalldatetime data type) where the time value in each row is current time + 6hrs.
I tried using the Getdate() function but it doesnt update. Instead it just provides a stamp of when the rows were created. You can see that I tried the script in this post. I thought it had worked but when I checked the table the next day the time had never changed.I would like to set the Default value for a column to Current Time + 6hrs
Thanks in advance for any help offered.

Add the following field to your view:
DATEADD(hour, 6, GETDATE()) AS Minimum_Departure_Time
Since you want it to change when you look at it, there is no reason to put it in the table. Just put it in your view since the view is dynamically created everytime it is run.

Related

Advanced DataGridView DateTime Filter

In my win form application I have used 'Advanced DataGridView'. For filter string columns it is working good but when i filter Datetime column the grid view becomes empty.
When i did debug it, i came to known that it is getting only dates and not dateTime from the column i.e
([Date_Time] IN ('11/04/2017', '12/04/2017', '13/04/2017'))
and this is the reason why my grid view become empty because there is no row with only date.
here is my code for 'Change filterString' event
Me.crossMatchBindingSource.Filter = dgvCrossMatchDetails.FilterString
So, my question is how can i include time in the filter.
I believe you are trying to bind a grid view to a data source, which uses SQL to extract data from the databases. I believe you can just amend your SQL as follows:
([Date_Time] between ('11/04/2017' and '14/04/2017'))
This should cater for times as well as dates.
You should just go to DataGridView properties and set "DateWithTime" to "True".
Then you are able to filter by Date and Time now.
Please correct me if i m wrong. whoever created AdvancedDataGrid, the code he/she wrote to filter can only filter the date and not the datetime. So i should split my datetime in two columns then i will be able to filter my dates. Actually i have done it and it is working perfectly but time column shows every record separately like text in the filter and not making grope of hours and minutes as excel does.

date and time not being added to table with correct default and datatype

I am using AnySQL Maestro 13.2.0.15 which is SQL-server based. I need the date and time to automatically be put in the column "added" of my table called "accntgs" with out me having to select the current date and time. I have added the field with the datetime data type and set the default to getdate(), but then when I enter a new record and post it, the added field is still null. I have also tried to use the timestamp data type, and when I post a new record with that, the added field says (bytes) and does not have the date or the time. How do I fix this and get the date and time the record is posted to show up.
I have also tried this:
ALTER TABLE accntgs ADD CONSTRAINT
DF_accntgs_added DEFAULT GETDATE() FOR added
and it didnt add the the date when the new record was posted either

Insert into datagridview column specific values in vb net

i am developing an app for windows in vb net.
I am stuck in the last part which is the following and i would like some help on to where should i look or do.My question:I have one database in mysql called patient.each patient have the usual columns(name,surname etc..).Apart from all the columns there is one column called 'time' and another one called 'date'.I have also one datagrid where these values are displayed.When a new user is to be added,all the fields are filled and in the 'time' he fills the time of visit.I would like to ask if there is any way to restrict the range of time according to date...for example to be able in the beginning before adding the new patient,to say that in august 30 of 2014 the range of time for appointments is from 9 to 10.So when the new patient is added on that date ,to book only between this range every ten minutes eg 9:10,then 9:20 and so on until 10.
I am really stuck and been searching the last week for a solution ,so any ideas on the implementation would be appreciated.
Thank you in advance..If you need some of my code let me know.
If you want to restrict the input data, you have to use the DataGridView's CellValidating event. There you can check wether the input is ok or not. If it's not ok, you can set the ErrorText field of the edited row, where you can explain to the user what's wrong with his input.
Have a look at this HowTo from the MSDN.

How do I add a countdown timer to a datagridView object?

I have a dataGridView object called dgvMonitor that will be used to display pending consultations that are required to be executed within a certain amount of time by a supervisor. The supervisor is given 24hours from the time he submitted an entry, into the program, to complete this task.
dgvMonitor is being filled with an SQL adaptor and once that is completed, I systematically add a new column (REMAINING_TIME) at index 0 or basically to the first column, in the DGV, after I fill the table.
Now, what I need to do is insert a timer, in each cell within column (REMAINING_TIME)
What I would like to do is use the date in column (DATE_SUBMITTED) which is located at index 12 or the 12th column, in the DGV, add 24hours to each date, in that column, and begin counting down. Once the counter is equal to 0, an event will be triggered.
I did some searching on here and all I could find was:
How to create multiple timer handler in vb.net
and
add computed remainingTime to each inserted row of a datagridview
but I couldn't figure out how to apply their scenarios to fit my condition.
I would really appreciate anyone's help. If you need more information to go off of, please let me know and I will edit my question.
Thanks.

VBA Excel: Add one second to a time

I'm working with a spreadsheet with two columns, in which one of the columns is a time. I have loaded the data into a dictionary using the time as a key. I want to look up the data corresponding to a particular time (easy), and then get the next data point so that I can compare their values. The data is recorded such that one piece of data is generated every second over a period of around two hours.
My question is, does VBA in Excel have a function which can automatically add one second to a time? Or do I need to manually write one?
Update: In addition to the answers below, I have also found the "DateAdd" function useful - I suspect it depends on the version of Excel being used.
you should be able to use Time(hour, minute,second) function to add a second to the time.
so to add 1 second to a date with something like Date(2012,1,16) + Time(0,0,1) which should result in a value of "2012-01-16 12:00:01 AM"
you can use TimeValue("00:00:01") for adding in this example 1 second