A drop-down with a list of week beginnings dates in VB6 - vb6

I have a drop-down box in my VB6 form, I was wondering if there was an easy way to have it displaying the dates for the week beginning for the next 4 weeks.
E.g. if it was running now it would have,
19/4/2009
26/4/2009
3/5/2009
10/5/2009

Here is a simple method that will do what you want.
Dim i As Integer
Dim myDate As Date
myDate = DateAdd("d", -Weekday(Now), Now)
For i = 1 To 4
Combo1.AddItem FormatDateTime(DateAdd("d", i * 7, myDate), vbShortDate)
Next i

Simply calculate the first day of the week, and then add 7 days.

Related

Day add in SSRS for weekday

i want to achieve the following I want to set the default date to the following business day. That would add one day for all weekdays unless it is Friday, if day is Friday than it add 3 days for Friday.
I am using the statement below but it is not working. It is adding 3 days for other days besides Friday in ssrs report.
= IIF(Weekday(Today()) <=3, DateAdd("d", 1, Today()), DateAdd("d", 3, Today()))
Example - 18/05/2018 today will be displayed 21/05/2018 And if date is 21/05/2018
then it will display 22/05/2018
Thanks for your answer.
I have created below logic on my local box and it works.
=DateAdd("d", IIF(Weekday(Today())=6, 3, IIF(Weekday(Today())=7, 2, 1)), Today())
I have added check that if Weekday returns 6(Friday) then add 3 days to Today date
else if Weekday returns 7(Saturday) then add 2 days to Today date
else add 1 day to Today date.

VBScript DateDiff month

I am having a problem about getting the month datedifference between two dates.
Here is a sample:
DateDiff("m","2014-10-17","2014-10-30")
The above code returns 0 months since it is less than a month. But,
DateDiff("m","2014-10-17","2014-11-01")
returns 1 which should not be since it is still 15 days.
My problem is I want to see if these two dates already exceed a month but it seems that it calculates 1 month only when the month part of the date is changed.
DateDiff calculates the span between two timestamps with the precision defined in the first parameter. From what you described in your question and comments you rather seem to be looking for something like this:
ds1 = "2014-10-17"
ds2 = "2014-10-30"
d1 = CDate(ds1)
d2 = CDate(ds2)
diff = DateDiff("m", d1, d2)
If diff > 0 And Day(d2) < Day(d1) Then diff = diff - 1
WScript.Echo diff & " full months have passed between " & ds1 & " and " & ds2 & "."
You can calculate day difference between two dates using 'DateDiff("d",date1,date2)'.
Then calculate number of full-month by dividing 30 days.
Following is an example.
monthDiff = int(DateDiff("d","2014-10-17","2014-11-01") / 30)
As you know, days of months differs by month. For example, November has 30 days and December has 31 days.
If you wish to use 30 days a month when first day is on November, and to use 31 days a month whe first day is on December, the code need a table of days of months and routine to handle month information.

How do I convert Oracle internal date to Excel date in Excel?

I have a .csv file which was captured from an Oracle database. The date in the .csv file is in the Oracle internal format (not sure what it's called as I'm not familiar with Oracle). It looks like 16474
When I look at that date in the app we use to access the DB, the date is 2/6/2013.
However, when I import the .csv file into Excel and format the column as Short Date, it shows the date as 2/6/1945
I did a random sampling, and it looks like the month/day is always correct, but the year is off by 68 years. I'm assuming this is because Oracle's "beginning of time" is different than Excel's "beginning of time"
Any way to fix this so the dates show properly when importing the Oracle data into Excel?
I don't have access to anything on the Oracle side .. just the .csv file, and Excel. I'm also ultimately importing the Excel file into Access if that helps.
So far, I formatted the Oracle date as Short Date in Excel, and inserted a column next to my date column (J) and used the following:
=DATE(YEAR(J1)+68,MONTH(J1),DAY(J1))
I'm not sure if that is 100% accurate considering leap years
EDIT: I think this code may do it:
Public Sub ReplaceData()
Dim RangeCell As Range
For Each RangeCell In Selection
If IsNumeric(RangeCell.Value) Then
lngDate = CLng(RangeCell.Value)
RangeCell.Value = DateAdd("d", lngDate - 1, "1/1/1968")
End If
Next RangeCell
End Sub
It seems that Oracle may begin on 1/1/1968. I'm not a DB guy but I think that number sounds familiar in other reading I have done.
Here is an example routine that would convert the Oracle date to Excel date, if the above assumption of 1/1/1968 is true.
Sub OracleToExcelCSVDates()
Dim rng as Range 'range of cells containing dates'
Dim cl as Range
Dim strDate As String 'date received from Oracle'
Dim lngDate As Long
Dim newDate As Date 'Converted date'
Set rng = Range("J1:J1000") '< modify this for the number of rows you use in col J'
For each cl in rng 'Iterate over the rng you defined above.'
'Capture the date from Oracle'
strDate = cl.Value
If Not Trim(strDate) = vbNullString Then 'ignore blanks'
'convert to Long data type'
lngDate = CLng(strDate)
'Add the # of days (lngDate) to Oracles base date of 1/1/1968'
newDate = DateAdd("d", lngDate - 1, "1/1/1968")
'Overwrite the cell value with the new converted date:'
cl.Value = newDate
End If
End Sub
More info about Excel dates:
Excel stores serial dates as "a number representing the number of days since 1900-Jan-0, plus a fractional portion of a 24 hour day: ddddd.tttttt . This is called a serial date, or serial date-time."
http://www.cpearson.com/excel/datetime.

Determine the amount of clicks required to reach a specific date using a JQuery calendar?

I have a jquery calendar for the start date of a project.
Using Watir (automated browser driver, a gem for ruby), I have a set date that I would like to enter in.
The calendar start date is always today's date, whatever that may be for the day it is used. I was wondering if there was a way that ruby can process what today's date is, and use the specified date provided by the user, to calculate the difference of months between them.
Here is an example of the Calendar plugin: http://jqueryui.com/datepicker/
example:
today's date is 30/10/2012, if there was a project that were to start on the 20/12/2012, that would be 2 months from now, so 2 clicks on the next month button.
Is there a way I could do this?
Here is how I approached a similar situation with JSdatepicker:
$today = Time.now.strftime("%e").gsub(" ", "") #one digit day of month without leading space
#browser.text_field(:id => /dateAvailable/).click
Watir::Wait.until(60) {#browser.div(:id => /dateAvailable_popup_cal/).td(:text => $today).exists?}
#browser.div(:id => /dateAvailable_popup_cal/).td(:text => $today).click
Set or grab the date.
Click the text_field that fires the JSDatePicker object
Wait until the calendar actually pops up
The current month is shown, so choose today's date number.
In your case, you also need to set the month. Whether prompting the user for this, or choosing "today", the theory is the same:
$month = Date::MONTHNAMES[Date.today.month] #etc
Pseudo-code making lots of assumptions (only future dates, month name shown on calendar as text, etc):
while !#jquerytablewindow.text.include?($month)
next_month_button.click
end
I don't see a specific advantage to my method versus counting each month, unless of course we add a month to the calendar one day and you still want your code to work!
You could do:
#End date converted to date object
specified_date = '20/12/2012'
end_date = Date.parse(specified_date)
#Start date (today - 30/10/2012)
today = Date.today
#Determine difference in months
number_of_months_up_to_today = (today.month + today.year * 12)
number_of_months_up_to_end = (end_date.month + end_date.year * 12)
clicks_required = number_of_months_up_to_end - number_of_months_up_to_today
#=> 2
Basically it is counting the number of months since the year 0 and then finding the difference.

How to select Monthly and yearly Dates?

Using VB 6
Using two DTPicker in my project, I want to select monthly and yearly like MM/yyyy and yyyy
Now am Using Daily Date’s like 23/02/2009 (dd/MM/yyyy), I want to use like Monthly (MM/yyyy) and Yearly (yyyy)
My Code
Public Function DaysInMonth(dte As Date) As Integer
Dim d As Date
d = DateAdd("m", 1, dte)
d = DateAdd("d", -1, d)
DaysInMonth = Day(d)
End Function
Private Sub Form_Load()
Dim dteFrom As Date
Dim dteTo As Date
dteFrom = Format(CDate(Year(Date) & "-" & Month(Date) & "-" & "01"), "yyyy-mm-dd")
dteTo = Format(CDate(Year(Date) & "-" & Month(Date) & "-" & DaysInMonth(dteFrom)), "yyyy-mm-dd")
dtpFrom.Value = dteFrom
dtpTo.Value = dteTo
End Sub
Above code is working for daily dates. I want to use monthly and yearly dates also
Now I am selecting a date it showing complete value of the date like 03-02-2009, I want to show monthly and Yearly data’s
Expected Output.
Monthly Date
03/2009 to 04/2009 – It should take a value of 01/03/2009 to 30/04/2009
05/2009 to 05/2009 – It should take a value of 01/05/2009 to 31/05/2009
Yearly Date
2008 to 2008 – It should take a value of 01/01/2008 to 31/12/2008
2008 to 2009 – It should take a value of 01/01/2008 to 31/12/2009
How to select monthly and yearly?
Need VB 6 code Help
You can set the Format on the DTPicker to 3 (dtpCustom) and the CustomFormat to MM/yyyy . This will display month/year format in the text section, but you will still get the full calendar on drop down.
If you want to disable the calendar, you can set UpDown to True. Then you will get up/down buttons instead of the dropdown.
You need to make sure that the hidden value (day part) is correct.
EDIT:
OK, from your comment I understand that you are happy with the date picker, but you want to display the result in a special format?
Example:
Date selected is 20/8/2009 and stored in a date variable a.
Display as 2009:
MsgBox Format(a, "yyyy")
Display as 08/2009:
MsgBox Format(a, "mm/yyyy")
Display as August, 2009:
MsgBox Format(a, "mmmm, yyyy")
Display as Aug, 2009:
MsgBox Format(a, "mmm, yyyy")
Is this what you want?

Resources