Inserting a 'day' column in Access - ms-access

I'm working in Access and currently have a column with a time stamp in the format DD/MM/YYYY hh:mm. I'm trying to insert a column next to it that only contains the relevent day in number format without the rest of the timestamp. I'm sure this is painfully simple but for some reason I can't figure it out.
Many thanks,
Matt

In a query, add the expression:
Day([YourTimestampFieldName])
In a form with a textbox, use this ControlSource for the textbox:
=Day([YourTimestampFieldName])
If relevent day in number format means something else than the day, please specify.

You have multiple options.
You can design to column to be a specific format in the table design view. This will enforce date formats for you. Its been a minute for me, but I believe it even works as you try to insert into that column.
You can use the FORMAT function on inserts, as getting data from another column/data type is what youre doing. its actual specific use is of:
FORMAT(yourColumn, "MM-DD-YYYY")
If you need more specifics, you can google the function.
You can set up a macro that will function like a trigger in normal RDMS's. This i envision will UpSert the value to the new column based on INSERT/UPDATE logic.
Let me know if you think this requires more assistance. I think this should be more than enough to get you started.

Related

My TDBgrid is showing 1899/12/30 in a Time Field

My TDbgrid is displaying "1899/12/30 23:00" in a time field. I have connected the database via a dynamic link , so i cannot change anything via design. I am aware that there is solution to this on StackOverflow but i cannot use the solution because my database is connected dynamically. Is there a way to display the time only.
Thank you.
This is by design, as the "zero date" value of DateTime is Access in 1899-12-30.
Thus, your time value of your sample is 23:00:00.
However, a DateTime value carries no format, so the solution is up to you - apply the format you wish to the value whenever you wish to display the time - in your case, the format will most likely be hh:nn (in VBA, don't know about Delphi).

Is it possible to use DateDiff in an IIF statement?

I have searched looking for help but can't find exactly what I need.
I am trying to find the total number of days between two date fields, however the initiating date fields could be from two different fields, eg Start Date, or amended Start Date. The end date will always be the same field.
The majority of the time there will not be an amended start date but I need a way to cater for the scenario that an start date has been amended.
I tried the following
=IIF(Fields!AmendedStartDate.Value is nothing, DateDiff("d",Fields!StartDate.Value,Fields!EndDate.Value, DateDiff("d",Fields!AmendedStartDate.Value, Fields!EndDate.Value)))
I get an error run a run this.
I am fairly new to Report Builder/SSRS so I am unsure if what I am asking for is even possible.
Thanks for taking the time to look.
You can't do Fields!FieldName.Value is nothing, instead you need IsNothing(Fields!FieldName.Value):
=IIf(IsNothing(Fields!AmendedStartDate.Value),DateDiff("d",Fields!StartDate.Value,Fields!EndDate.Value),DateDiff("d",Fields!AmendedStartDate.Value,Fields!EndDate.Value))
Alternatively, you could create a Calculated Field (called say, StartDateToUse) with a similar expression:
=IIf(IsNothing(Fields!AmendedStartDate.Value),Fields!StartDate.Value,Fields!AmendedStartDate.Value)
And then refer to this field in your main expression to get the result you want:
=DateDiff("d",Fields!StartDateToUse.Value,Fields!EndDate.Value)

SSRS - Is there a way to restrict date/time input parameters to date only? (Not report output field format.)

I am writing an SSRS report that has several parameters including a couple of date fields. I do not want the user to be able to enter time information in either date field, but SSRS only has the Date/Time data type. Is there a way to force these report parameters to act as date only, and can I set a specific format (e.g., dd/mm/yyyy)? I would like to keep the built-in date-picker-calendar functionality.
I do not want to write my own report parameter web page because if I did then this one report would be the odd one out given that all of our other reports (which don't use date parameters) work fine with the built-in SSRS parameter entry functionality.
Perhaps the answer is that you can't do it with the built-in options, but that seems crazy - how could something so obvious have been overlooked?
The Google and Stackoverflow searches I've done only gave me ways to set the format in the report output (actually there are a number of cases where people have asked a question similar to mine and only received answers about setting the output format).
The problem is that you are using parameters that get timestamp information.
For example, if you are using Now() in your expressions- you will be asking for the current date AND the current time. However, if you use Today()- you will only be asking for the current date.
=Today() 'returns date only
=Now() 'returns date and current timestamp
Useful references:
http://msdn.microsoft.com/en-us/library/ms157328(v=sql.90).aspx
http://msdn.microsoft.com/en-us/library/ms157328.aspx
To answer my own question based on research I've done since asking it: it seems it is not possible to control how SSRS handles user entry of date/time values in parameters. If there is a need to restrict to date (or time) only or do cross-field validation then you need to implement your own front-end - which unfortunately for my specific business case doesn't help.
In my experience it has only given me the date and time when the filed you are selecting from contains both date and time. I have found if I am selecting on a date only field then I only get the date in the parameter
There is a way, but it will require you to CAST your date as Varchar(10) in your parameter dataset.
Next,You'll have to choose "Data Type:" as Text under Parameters section.
Again, you'll have to make sure your SQL code re-converts it into date again. I do not prefer this way, but users really wanted to see date without time.
Let me know if you'd like screenshot or more detail.

MySQL: find out what date a row was added to a table?

I added a new column to a table called price_request_date because I now need to track the date each one was made. I made it so new ones enter the current date when they insert a new row. I was just wondering if there was any way to fill in the previous rows with the dates they were entered? I don't know if MySQL keeps track of that sort of thing or not, but worth an ask. Thanks!
There is not. There is no way to automatically backdate a timestamp field with the original creation date if it weren't already set at creation time.
Frustrating - I know.
nope. it is good to always include LastChgID and LastChgDate on tables like this, do that next time from the get go...

SSRS: How to make a sum that only includes the last item in a group

I have an rdlc report file, and I am trying to make a sum which can only include the last item in each group. I have a table kind of like this:
Place = ? (Group header 1)
User = ? (Group header 2)
Date =Last(Fields!Number.Value) (Group header 3)
Number =Fields!Number.Value (Detail row)
So, in other words, in User there, I want a sum of Date... if that made sense...
The Numberrows contain many numbers per Date. But Date shows only the last number for that day, because the rest doesn't count (but must be displayed) In User I want to sum up those last numbers for all the dates for that user. And same with Place (which would be the sum of every last number for every day for every user).
Could anyone help me with this? I tried the obvious (to me at least) =Sum(Last(Fields!Number.Value)), but (also tried to specify the group in those functions, but didn't make a difference because) I get an error when I try to compile which says:
The Value expression for the textbox 'numberTextbox' contains an aggregate function (or RunningValue or RowNumber functions) in the argument to another aggregate function (or RunningValue). Aggregate functions cannot be nested inside other aggregate functions.
Which I guess kind of makes sense... but how do I do this then?
Update: I have solved the issue by adding another column, and copying those last numbers into that column. This way I can display all the numbers, and do the summing on the column that only contains the ones that is going to be in the sum. I am still very curious to if anyone have a solution to my original problem though... so please post an answer if you do!
Not sure I understand exactly what you're trying to do. Maybe something like =Last(Fields!Number.Value,"Group 1") + Last(Fields!Number.Value,"Group 2") + Last(Fields!Number.Value,"Group 3"), instead using a sum function?
the easiest way to do this would be to modify your dataset to only include the records your are displaying in the date field, that way you could just use a simple sum() instead of trying to do something weird and screwy and might not work.
Modifying the data set may really be the simplest solution, but if you really wanted to do this without complicating the query you could try "custom aggregation".
The exact techniques for this depend on the version of SSRS, and my understanding is it didn't really work that well before SSRS 2008.
The idea is, you write some custom code to maintain an array containing the last value for each date. One function updates the "last value" for a date, and another sums the values in the array. Your header calls the latter function; you conspire to cause the former function to be called once for each detail row before the header is processed.
Here's a blog with a write-up that explains the technique in SSRS 2008.
It also gives some insight into how you can try to make this work in SRSS 2005, but again apparently that's not as reliable.