Issue when retrieved date value is greater than 2030 from SQL to vb.net datetimepciker - sql

Retrieving Date value from sql into datetimepicker in Vb.Net form using sql data table. For dates with year 2030 or more, value is displayed as 1930 in datetime picker. Please help in solving this issue.
Code to retrieve value:
dtpDate.Value = sqlDT.Rows(i)("StartDate").ToString
For example,
If retrieved value of sqlDT.Rows(i)("StartDate").ToString is'10/30/2032'
then dtpDate value is displayed as '10/30/1932'.
This code is working fine for all the dates till 2030 year.

DataTimePicker.Value is of type Date.
You should give value of correct type
dtpDate.Value = sqlDT.Rows(i).Field(Of Date)("StartDate")
When working with vb.net you should set "Option Strict" setting to On in project settings or locally for the file writing Option Strict On on the first line of file.
In your case with Option Strict On you get compile error "String can not be converted to Date", which possible saves your time.

Related

How to convert dates to valid format in Google Data Studio?

I have a google sheet with dates in europian format ( 15.09.2020 08:40 ) . When importing the sheet to data studio it detects this field as text. I try to change it to DATE but get error "Cant convert". Maybe becouse its in european format? Anyone know how to change this? I have tried formatting in google sheets with no luck...
You have to convert it yourself, with the european date as as string in the field your_field, create an additional field with following formula:
PARSE_DATETIME("%d.%m.%Y %H:%M:%S", your_field)
The details for date converting/parsing can be found here:
https://support.google.com/datastudio/answer/9739558

How to use UserForm Values for multiple things

I have UserForm1 which is a multipage userform and I am trying to access the information that was gathered through the form in a sub located in Module1. This sub will need to access several different values and do different things with those values so this is going to be a multipart question.
I have the below code in which I attempt to use one of the values as the upper limit of a For Next Loop. However the current problem is that when the code reaches this line it jumps to the Userform_Initialize routine.
For X = 1 To UserForm1.LocalOffer.Value
Second part of this question comes from inside the For Next loop from above. Where I have the below code. Which would ideally allow me to cycle through a series of similarly named Textboxes from the userform. Not even sure if that will work as the code keeps breaking before getting to that part.
Range("B" & X).Value = UserForm1.Controls("LocalTier" & Tier).Value
Last Part of this question if I have a Textbox in the userform that contains a date in the format 1/18/2015 is there a way for me to grab just a portion of that date say for instance just the Day or just the last digit of the year?
I am using Excel 2013 but the file will be ran on Excel 2007
Edit:
Turns out that problem 1 was fixed by not closing the userform with the X button but instead adding a line to hide the userform when you hit the last button. As it turns out my code for the second question worked just fine once i got past that. Only question left is the last one which I have no ideas on.
As from the comments, I see you don't need anymore to know about points 1 and 2, I will hence limit my answer to the point 3.
Last Part of this question if I have a Textbox in the userform that contains a date in the format 1/18/2015 is there a way for me to grab just a portion of that date say for instance just the Day or just the last digit of the year?
You can use either string manipulation, or date conversion.
Let's assume the Textbox is called myDateTextbox
String manipulation
Among the string manipulators that VBA provides, I would cite Left() and Right().
For example:
last_digit_of_the_year = Right(myDateTextbox.Text, 1)
will return you the last character of the string. On the other hand:
first_digit = Left(myDateTextBox.Text,1)
will return you the first digit of the string.
You can use the Len(myDateTextBox.Text) built-in to return the current length of the string.
Date conversion
You can simply convert your string into date using the CDate() function. Please note this function will return an error if you pass an invalid string. If your textbox contains 24/01/1990, you can first convert the string into a date:
myDate = CDate(myDateTextBox.Text)
Hence, you can retrieve day, month or year like this:
myYear = Year(myDate)
myMonth = Month(myDate)
myDay = Day(myDate)
Please note that CDate recognizes date formats according to the locale setting of your system.. Hence, if the format in the TextBox is not the same than the one of your system, then consider manipulating the string before to adapt it to the proper format. For example, if your system has settings DD/MM/YYYY and your textbox shows a MM/DD/YYYY type, you can "adjust it" as follows:
wrongFormat = myDateTextBox.Text
splittedDate = Split(wrongFormat,"/")
goodFormat = splittedDate(1) & "/" & splittedDate(0) & "/" splittedDate(2)
If wrongFormat was 1/18/2014 but your system would like to read it as 18/1/2014, it's now fine because goodFormat will be equal to 18/1/2014 after the split and re-build.

Date Parameter Validation in Pentaho Report Designer

How can i validate date parameters in a pentaho report designer.I am using "fromDate" and "ToDate " parameters in my report/prpt.Because if i am selecting particular date range i will get that particular date ranging values only..It is working fine...
But if anyone is selecting date range like " FromDate > ToDate " i want to show some notifications like " wrong date selection " like dat..
Is it possible in Pentaho Report Designer? Or by using some java SCript?
Can you provide more context? I don't seem to understand your question.
But try to use the IF formula to your parameter (since I believe you are using it as a field in your report) to render the value to be "Wrong date selection" if the start date is greater than the end date or vice-versa.
In a Pentaho report designer, take a label for validation and edit a value in the attribute tab as -
=IF([FromDate ]>[ToDate];"'ToDate' should be greater than or equal to 'FromDate '";
IF([FromDate ]>TODAY();"'FromDate ' should be less than or equal to 'current date'";""))
Hope this answer helps.
screenshot

Date format issue in SSRS

I have an issue with date format in my SSRS. I am saving date from DateTimePicker to database. From there I am taking display in my datagridview using following
dgv.items(0,2).value=Format(Cdate(dsSaver.tblInv.rows(0).items(0)),"dd-MMM-yyyy")
This displays it correctly (04-Nov-2011) but when I take date from the same database to my SSRS using
="Dated: " &Format(cdate(Fields!InvDate.Value),"dd-MMM-yyyy")
It displays it like 11-Apr-2011.
I have tested all winforms fare displaying it right but all SSRS are displaying it wrong.
Please advise.
A couple of things are going on here. The date is being saved appropriately but is being displayed incorrectly due to your formatting options. This line is quite problematic:
="Dated: " & Format(cdate(Fields!InvDate.Value), "dd-MMM-yyyy")
CDate takes a value, generally a string, and converts it to a date, which you are then taking and formatting back into a string. Now, by default reports are set to have their Language property set to English (United States) so the CDate function is taking the string representation of the date 04-Nov-2011 to be 04/11/2011 which it is then converting, using the US format of MM-dd-yyyy (not the Pakistani one) into being the date 11-Apr-2011 because it thinks the month comes first.
So, you should change your Language setting of your report to =User!Language so that it supports whatever the user's language is and will format things appropriately. This may be enough to make your expression work.
Regardless, if Fields!InvDate.Value is being supplied as a date field (as it should be) there is no need for the CDate function and this should work:
="Dated: " & Format(Fields!InvDate.Value, "dd-MMM-yyyy")
There is also the FormatDateTime function but unfortunately it doesn't support the format you want to use.
Have you looked at the RDLC options for Formatting a Report: Format the Date?

SSRS Date/Time Parameter changing how it is displayed on the report

Is there a possibility of changing how the SSRS DateTime parameters are displayed on the report,
i have a parameter with a date/time data type, when the report run, users see a date format that included time in it , users don't want to see time in the parameters, it should only be a date like <2/6/2010>, is there a way to do this in SSRS
Thanks in advance
On Embedding SSRS report on a .NET web form, using Report Viewer control, and pre-populating the date parameter with values, from code. The parameters after that will keep the same format as the date you provided them with from code.
so i was populating my parameter from C# like this
var startDate = DateTime.Now;
var parameters = new List<ReportParameter>
{ new ReportParameter("START_DATE", startDate.ToString())};
ConsumptionReportViewer.ServerReport.SetParameters(parameters);
this gave the START_DATE paremeter with dates of this format "3/9/2008 4:05:07 PM"
and later changing the dates from the calender input, the format remains the same
i changed the format on the code to
new ReportParameter("START_DATE", String.Format("{0:d}",startDate)
this gives the START_DATE paremeter wiht dates of this format "3/9/2008"
and now when i change the datees from the calender input, the format remains the same