MS Access Convert text to shortdate - ms-access

Hi all i have a question,
I have a field in the table whereby its a text field and i want to convert it to date field. Though all the values within are in date format however its not convenient to change because of some circumstances.
Thus i need to change the text field to date field so as to do a comparison or validation.
Im using MS access SQL for this project so please help me
I have tried
TRANSFORM Count(Registrants.[Field1]) AS CountOfField1
SELECT Registrants.[Country] , Count(Registrants.[Field1]) AS [Total Of Field1]
FROM Registrants
WHERE Cast(Registrants.Field1 As Date) Between #15/6/2014# AND # 30/8/2014#
GROUP BY Registrants.[Country]
PIVOT Format([Field1]);

Cast does not exist in MS Access sql.
Use DateValue instead :
WHERE DateValue(Registrants.Field1) Between #15/6/2014# AND #30/8/2014#
See here for sample usage and syntax.
Also I noted a space in your 2nd date, I assume that's a typo.

Related

MS Access Calculating date differences if Dates are Short Text

Is is possible in a Table to Calculate differences between Dates if the Value in the field is considered "short text"?
I am working to convert an Excel macro database into Access one and I have imported the data from the Excel file into an Access Table.
however i realized 2 feilds that count up until closure are now just fixed numbers but need to add up as each day passes until closure
when i imported the Dates became Short Text.
is there an expression that would handle this situation?
Each record has a serialized non repeating ID number seperate from access as well.
Dates I have are
OfficialissuanceDate,
DatePlanSubmitted,
DatePlanCompletedSubmitted,
DateClosed,
I need 2 calculations that increments daily when DateplanSubmitted and DatePlanCompletedSubmitted are null
Both comparing to OfficialIssuanceDate. then stop counting when they are no longer null. (have a date in updated to the record) and retain the value.
I have tried to Google calculating Dates but i get DateDiff function which doesnt appear to work. I've used Access and taken a class on it but never really made a new DB from scratch
Dates in a text field are not actual dates, just strings of characters. A Date/Time field stores value as a double number then displays in a date structure - "dd/mm/yyyy" is Access default structure.
Sometimes Access will do implicit conversion of data but not in this case. Either change field type to Date/Time or do conversion with CDate() function. However, you will find that conversion functions error with Null input.
Arithmetic operation with Date/Time field type is possible. However, arithmetic when any term is null returns Null so have to deal with that. One way uses Nz() function: Nz([DateClosed], Date()) - [DateOpened]. Unfortunately, Nz() is not available in table Calculated field type, so do that calc in query or textbox. Most developers avoid table Calculated field type. If you really want to use, expression would have to be: IIf(IsNull([DateClosed), Date(), [DateClosed]) - [DateOpened].

Summation Error (SSRS)

From the image above, I want to sum the Time Spent column in my SSRS report. The issue is that this is not an int column but a varchar (after finding the difference between two datetime columns). I want my result set to be in the format - 00:00:00 (form of hh:mm:ss).
The sql query looks like:
CONVERT(Varchar(10), Dateadd(Second, DATEDIFF(Second,StartDate,FinishedDate),0), 108) AS SpentTime
What do I have to do to get the right values back?
Thank you.
Instead of using VARCHAR formatting in the SQL procedure, you can send the TimeSpent as a time data type and then you can use the expression below. You can then format the time within the report itself instead using text box properties.
=TimeSpan.FromTicks(Sum(Fields!TimeSpent.Value))

dd/mm/yyyy date format in SSRS

i'm trying to specify dd/mm/yyyy dateformat for date/time parameter in SSRS 2008 R2.
My computers datetime format is mm-dd-yyyy.
My requirement is, i want to show date format at dd/mm/yyyy irrespective of the system/server date format.
I've already tried CDate(Format(Today,"dd/mm/yyyy")) which didn't work. one very strange thing i observed is, it shows dd/mm/yyyy format only for dates on or before 12-MM-yyyy, and 13 onwards it gives error: Conversion from string '25-04-2014' to type Date is not valid. (Possibly it is trying to map 25(daypart) with MM-dd-yyyy (month part)) which is out of range of total months i.e. 12)
my research on internet says it is a bug in BIDS 2008.
What do i do to display date as dd/mm/yyyy ??
I don't have enough reputation to comment, but I did notice that you failed to put "()" after "Today". If I'm not mistaken you must put Today() for that function to work. Also, you might want to try putting CDate Around the Today() function. You shouldn't need it, but it's worth a shot. Also, for some odd reason, in my experience, you must capitalize MM for format to work correctly.
Like #Aditaya said, it should be =format(Today(),"dd/MM/yyyy")
The expression I usually use is:
=FormatDateTime(Fields!Date.Value, DateFormat.ShortDate)
However, this may be region specific.
Rather than writing an expression to do the formatting, you can also use the Textbox Format Property. But first you need to make sure that the data is in a date format. So use the CDate function on your column like this:
=CDate(Fields!Date.Value)
Then in the textbox properties go to the Number tab. Select Date for the category. Then you can select whichever format you want or use a Custom format. This will change how the column displays when you run the report.

How can I sort by date in ms access 2007?

Just want to know how do I sort a text column that shows data in date format mm/dd/yyyy.
You will first have to convert to a date to get a proper sort. This is a query that converts Datetext to RealDate, and then sorts on that column (field). You can also click the header to choose the sort order.
SELECT
t.ID,
t.Datetext,
DateSerial(Mid([Datetext],InStrRev([Datetext],"/")+1),
Mid([Datetext],1,InStr([Datetext],"/")-1),
Mid([Datetext],InStr([Datetext],"/")+1,
(InStrRev(Datetext,"/")-InStr([Datetext],"/"))-1)) AS RealDate
FROM Table t
Order By 3
You can use IIf to avoid errors from null:
IIf([Datetext] Is Null,Null,DateSerial(
Mid([Datetext],InStrRev([Datetext],"/")+1),
Mid([Datetext],1,InStr([Datetext],"/")-1),
Mid([Datetext],InStr([Datetext],"/")+1,
(InStrRev(Datetext,"/")-InStr([Datetext],"/"))-1))) AS RealDate
In a comment you said this is a "text column displaying date from a sql table". I'm unsure what you meant by that, but I think the situation could be simpler if you can convert the text column to an actual Date/Time column.
If you're importing data from SQL Server into Access, convert those text values when you pull them in to Access.
If the Access table is a link to a SQL Server object, create a view in SQL Server which casts the text date column to an Access-compatible date type. Then on the Access side, replace your existing link with a link to the view.
If you need to edit the date values in Access, not just display and sort them, include both the original text column and the transformed date version in your view. Do your Access edits to the text column; sort on the Date/Time column.

Removing the timestamp from a date in an Excel pivot table connected to a cube

So I have a cube created in Analysis Services 2008 R2. The cube has some dates on one of the non time dimensions. When I put the date on the filters in the excel pivot table, it always puts the date as, for example, 01/18/2012 00:00:00.000. Is it possible to exclude the timestamp from it? I tried using the format cell in excel, but it does nothing to it. I also tried converting from the source (The source is a view from a SQL Server database) from datetime to date using Convert(date,fieldWithDateInfo), and that drops the timestamp, but then Excel treats the field as string, and then the filters start acting really funky. Any suggestions?
check the "format string" property for the attribute...I believe the "shortdate" option is what you want.
Add a calculated column to your time dimension using the code below
CONVERT(Varchar, [YOUR DATE COLUMN], 103) AS Date_UK
and change the 'Name Column' attribute to your new calculated column for the datetime dimension attribute