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
Related
maybe you've experienced this, too. When I get involved into a project that is already running the project lead or scrumm master forward me appointment series like daily stand-ups or similar and the series started long before the day I receive the invitation.
Let's asume the following as example:
The series starts on January, 11th 2021 (Monday) and re-occurs every week.
I receive the invitation in my inbox on March, 16th 2021 (Tuesday).
When I look into my calender I will see this appointment in January, February etc. although I didn't participate back then because I wasn't assigned. To keep my calender in a way that it shows what really happend I have to manually remove all those occurances.
What I want to archieve is this:
The invitation enters my inbox.
Application_NewMailEx is triggered and runs a piece of VBA code that checks for a series like the following.
(...)
If TypeName(objInboxObject) = "MeetingItem" Then
Set objAppt = objInboxObject.GetAssociatedAppointment(False)
If Not objAppt Is Nothing Then
If objAppt.IsRecurring Then
Set objRecurrPatt = objAppt.GetRecurrencePattern
If Not objRecurrPatt Is Nothing Then
(...)
That's easy to handle but now the tricky part that I cannot find a solution anywhere and I really hope one of you can help me.
How I can I find out the NEXT FUTURE occurance starting from TODAY (the date I received it)? In the example this would be March, 22nd 2021. Especially if the re-occurance pattern is more complex than in the example.
Then I would replace the start date of the series with this calculated date and save the MeetingItem. If I accept it in the normal Outlook window I will have one calendar entries in the future and none in the past.
Analyzing the RecurrencePattern object you can find the date of the next occurrence. Then you can use the RecurrencePattern.GetOccurrence method which returns a specific instance of the AppointmentItem object on the specified date. The GetOccurrence method generates an error if no appointment of that series exists on the specified date.
I'm working in MS Project where the entire project duration is one hour.
My goal is to run a VBA sub when the program opens, to format the project schedule date to the "12.33 pm" style.
I've searched https://learn.microsoft.com/en-us/office/vba/api/project.application.dateformat to find a solution, but can't figure out the right syntax.
DateFormat(ActiveProject.Tasks) = pjDate_pjDate_hh_mmAM
I'd like to call this macro from my "open on macro" so the schedule date format changes to "pjDate_hh_mmAM".
The setting you are looking for is the DefaultDateFormat property of the Application object. This is the equivalent of going to File: Options, General tab: Date format.
Application.DefaultDateFormat = pjDate_hh_mmAM
You might consider capturing the current setting and restoring it later as it is an application-level setting and all projects opened will reflect this date format.
To summarize my problem, I'm currently having the exact same issue as the person from this question here. I'm trying to parse a US date into an Excel sheet that has German as default and gives me a type mismatch on most of the dates because of it.
SetLocale sounded like the perfect solution to my issue, but after a minute of further research I discovered that GetLocale and SetLocale are apparently not supported in VBA.
It sort of worked when I assigned the parsed date to a String variable (I end up with a column using either MM/DD/YYYY or DD/MMM/YYYY format depending on whether or not I had a type mismatch, as long as I use On Error Resume), but I need them in a MM/DD/YYYY date type/format in order to compare all the parsed dates to a specific date in another cell (attempting to determine if the site has had any updates since the date entered in the specific cell).
I've also tried doing TimeStamp = Format(TimeStamp, "MM/DD/YYYY") (TimeStamp being a variable containing the parsed date), but it doesn't seem to be working- most likely due to the type mismatch error.
If anyone knows a VBA equivalent of the SetLocale function used in the linked question for me to try out, I would greatly appreciate it. If there isn't any, I'll be happy to amend my question and add my current code here to try and hammer out a solution together.
Thank you for your time and your help.
If you know they are all in US format, you can use a function like this:
Function ConvertUSDate(sDate) As Date
ConvertUSDate = Evaluate("DATEVALUE(""" & sDate & """)")
End Function
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
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?