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

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)

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.

If Else Formula for Date field in Crysal Reports that keeps Date format - not string

I have a formula in Crystal Reports to convert for a particular date. The formula is working, but converts the field to a string, and I need the field to be a date as I am exporting as a CSV file and then loading data to a table.
Is there a way to use this same logic but have the field remain as a date
and not a string? Below is the current logic that I am using:
if totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'dd/MM/yyyy') = "01/01/1800" then
"01/31/2099"
else
totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'MM/dd/yyyy')
Maybe like this
if totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'dd/MM/yyyy') = "01/01/1800" then
"DATE '2099-31-12'"
else
"DATE '" & totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'yyyy-MM-dd') & "'"
Or use the TO_DATE() function.

Get weekday of arbitrary date with applescript

I'm working on a script to create a table of contents. The format for each item of this toc is: weekday, month day. Example: Sunday, September 1. I have a date in the format of "09/01/2018". Can I use this date to get the weekday? When I try the following I get the error "BBEdit got an error: Can’t get weekday of date "09/01/2018"."
set theDate to theMonth & "/" & theDay & "/" & theYear --> "09/01/2018"
set theWeekday to (weekday of date theDate)
I'v also tried setting theDate "as date" to which it says "Can’t make "09/01/2018" into type date." And I've also tried adding "tell application "{BBEdit, Finder, System Events}" to set theDate..." and each one gave the same same error as above.
The only info I can seem to find when googling is how to get currentDate or some other date based on whatever "today" is. Nothing for just a random date, which is what I need.
I'm sure I'm just missing something pretty simple here, but I'm pretty new to AppleScript so any help would be greatly appreciated!
Thanks in Advance!
The most reliable (and locale independent) way is to create the date with current date and set the properties
set theMonth to 8
set theDay to 14
set theYear to 2018
set currentDate to current date
-- the first `day` avoids an overflow error
tell currentDate to set {day, year, its month, day} to {1, theYear, theMonth, theDay}
set theWeekday to weekday of currentDate
or with a litte help from Cocoa
use framework "Foundation"
set dateComponents to current application's NSDateComponents's alloc()'s init()
dateComponents's setYear:theYear
dateComponents's setMonth:theMonth
dateComponents's setDay:theDay
set theDate to (current application's NSCalendar's currentCalendar()'s dateFromComponents:dateComponents) as date
set theWeekday to weekday of theDate

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 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