How to select Monthly and yearly Dates? - vb6

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?

Related

PowerBI unable to detect time type in get data

I get data from a folder where my file name has format Watches_20220315_095127 its in date and time format. But Power BI is unable to detect when the time starts with "0" i.e 095127 it displays error. Can you please help me. I need that time from file name to be used in powerbi report. Power BI works fine when my time has the following format.
Watches_20220315_105127
Watches_20220307_184253
Watches_20220301_144421
PowerBI not detecting as time for below format
Watches_20220315_095127
Assuming that you have the file name as a column in Power Query (PQ), you need to convert that text into a format that PQ can turn into a Date. You can do something like this by getting the sections of the string using Text.Range (Where [Column1] is the name of your column).
DateTime.FromText(
Text.Range([Column1], 8, 4) & "-"
& Text.Range([Column1], 12, 2) & "-"
& Text.Range([Column1], 14, 2) & " "
& Text.Range([Column1], 17,2) & ":"
& Text.Range([Column1], 19,2) & ":"
& Text.Range([Column1], 21,2)
)
This will split out the text into a YYYY-MM-DD HH:MM:SS format that can use DateTime.FromText to convert it into a date time.
You will have to set the field to be a date time type for PQ and then DAX to pick it up as a date time. In the below example the 4th row that has a time of 09:30:01 will now be converted to a correct date time.

change year in date irrespective of date format using vbscript

I want to only change year in the date irrespective of date format. For example if date=05/20/2019 0r 05-20-2019 then it should change to 05/20/2017
Just use DateSerial() to replace the Year component.
Call SetLocale("en-us")
Dim oldDate: oldDate = CDate("05/20/2019")
Dim newDate: newDate = DateSerial(2015, Month(oldDate), Day(oldDate)

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.

How to get selected day/month and year from vb datepicker

in a datepicker i use DateValue(Now) to get the current date . it gives date-month-year
but i require to store only the month value from the same datepicker. wht shoud i do ?
The month can be extracted from the date using the Format$ function:
Print "Month is ";Format$(yourDateValue,"mm")
See this page for all the possibilities.
To get the month as a string use Format as Richard suggests
MsgBox "Month name is " & Format$(yourDateValue, "mmm")
To get the month number use DatePart
MsgBox "Month number is " & DatePart("m", yourDateValue)

A drop-down with a list of week beginnings dates in 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.

Resources