Difference between .Value and .Text of a DateTimePicker - vb.net

I would like to know the difference between the two.
When I display as VIEW the result is - 12/27/2013 1:48:26 AM.
When I display as TEXT the result is- Friday December 27, 2013
Which is the better choice. I have been told that if date formats are different in pcs (for example one pc has dd,mm,yyyy and the othe pc has mm,dd,yyyy), the Datetimepicker may show error.

DateTimePicker.Value is the DateTime represented by the control
DateTimePicker.Text is HOW the control shows its date to the user according to the Format property
A DateTime value has no inherent format, it is just a numeric representation of a date. The way in which this numeric value is presented to the user is the Format of the date. This format is controlled by the regional settings of the local PC or the server. But it could be changed using various format strings.

DateTimePicker1.Value Will display your Current DateTime Value
DateTimePicker1.Text Will display your Format like Custom , Long, Short
Your default format is Long, that's why is showing DateTimePicker1.Text as Friday December 27, 2013

Related

How to see if a week past from a specific date?

I am making a VB.Net WinForm application. In which every week a setting will have to get reset and another setting(the date) will have to be updated.
For example:
The date is 7/17/18. On the 7/24/18, the setting will be reset and the date setting will be 7/24/18 so the function can go on. I know how to update and reset the setting. I just don't know how to say "a week from this date".
Thanks in advance for the help!
The easiest way would be to create an application level setting with user scope to store your last date, then you can compare the current date with the stored date to see if 7 days have past.
There are a few ways you could handle it, but to avoid culture issues, personally I have found that the easiest way is to store the date as a string in the international date format, so no matter what format the system uses for dates, the date will ALWAYS be in a recognisable format.
This method eliminates problems that could come up if the system's regional settings change:
My.Settings.DateSetting = Date.Today.ToString("yyyy-MM-dd")
To see if a week has passed from your previous date:
If Date.Today >= Cdate(My.Settings.DateSetting).AddDays(7) Then
'Do your stuff here
' ...
'Add one week to the previous date and save the setting
My.Settings.DateSetting = CDate(My.Settings.DateSetting).AddDays(7).ToString("yyyy-MM-dd")
My.Settings.Save()
End If

VBA interpretation of input date

I have this annoying date format inconsistency with Excel VBA. I have a source text file, which has dates in format of dd/mm/yyyy (i.e. the sane format). But I need to convert it to yyyy/mm/dd (for consistency, I also set up this format as default in my computer).
When I export this text file into database, if both of the dd and mm values are less than 12, VBA treats them as mm/dd/yyyy instead of dd/mm/yyyy. Even I am very confused about this non-standard date format, poor VBA.
For example, I have 06/08/2015 in text file, which is 6th August, but CDate("06/08/2015") returns 2015/06/08, i.e. 8th June. But if the text file has 15/08/2015, VBA can identify it as 2015/08/15.
How to tell VBA that 06/08/2015 is in dd/mm/yyyy format?
Any help with this annoying and tedious task would be greatly appreciated!
Use DateSerial() instead of CDate():
Dim d$
d = "06/08/2015"
MsgBox DateSerial(Right$(d, 4), Mid$(d, 4, 2), Left$(d, 2))
This way you control which bits of the date are which.

How to Format VBA TextBox To Long Date

I have a textbox for date display which shows the date in this format: 17/04/2012 but I would like to format it to shows up like 'April 17, 2012'. I tried this code
UserForm1.txtDate = Format(Long Date)
which I am getting syntax error from compiler.Can you please let me know how I can do it?
Thanks
there have been couple of posts on this. Culprit seems to be your system date format. Use of short, medium, long formats will change the result when the system settings change.
In US systems mainly it's done as, e.g. Format$(yourdate, “dd/mm/yyyy”)
Where as European systems, e.g. Format$(yourdate, “short date”)
If we look at explicitly defining your format, you are formulating your regional settings!
Good e.g. short date won’t always be mm/dd/yyyy but could be dd/mm/yyyy. That’s the key advantage over actually specifying the format. Simply you can change how you want your date to look like instead of depending on the system (with or without your knowledge).
When we first encountered this, we had some making the VBA apps and sending it over to another in some other place where they have own localized system date format. Your phone rings... ;)
Short/Long Date: Display a date according to your system’s long date format.
Medium Date: Display a date using the medium date format appropriate for the language version of the host application.
In your case you could use,
UserForm1.txtDate.Value = Format$(Date,"mmmm dd, yyyy")
Or to be super-safe,
Dim dtDate as Date
dtDate = DateSerial(Year(Date), Month(Date), Day(Date))
UserForm1.txtDate.Value = Format$(dtDate, "mmmm dd, yyyy")
Hope that helps.
References

Format of Date Time Picker

dtpPurDate.CustomFormat = "dd-MM-yyyy"
dtpPurDate.Text = DT.Rows(i)("PurDate")
In Access, PurDate is 1/1/1900 but in date time picker it's shown as 01-01-2000. At this time, short date format of system regional setting is like
If it's d/M/yyyy, it's shown as 01-01-1900.
How should I set the date time picker whatever regional setting is?
You're using the custom format string dd-MM-yyyy. With this custom format string, the - character is treated as a literal, and copied to the result string unchanged. Thus, all of your dates will use - as the date separator, regardless of your environment's regional settings.
Instead, you want to replace the literal - with the magic /. This is a special value that indicates to the control you want to use the appropriate localized date separator, as retrieved from the DateTimeFormatInfo.DateSeparator property of the current culture.
So your custom format string should be re-written as: dd/MM/yyyy.

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?