Option Explicit
Sub ForNight_1st_DayOfMonth_ChangeMonth()
Dim myTime, myMonth As String
Dim curTime As Date
Dim curDay As Long
curTime = Now
curDay = Day(curTime)
myTime = Format(Time, "hh:mm")
myMonth = Format(Date, "mm")
Debug.Print myMonth ' format "mm"
If curDay = 8 And myTime <= "06:30" Then ' For night 1st Day of Month
myMonth = Format(Date, "mm") - 1 ' become format "m"
Debug.Print myMonth
Else
Debug.Print myMonth
End If
End Sub
Option Explicit
Sub ForNight_1st_DayOfMonth_ChangeMonth()
Dim myTime, myMonth As String
Dim curTime As Date
Dim curDay, curDate As Long ' curDate Declared as Long
curTime = Now
curDay = Day(curTime)
curDate = Date 'Format Date is General with value "42529" as Long
myTime = Format(Time, "hh:mm")
myMonth = Format(Date, "mm")
Debug.Print myMonth ' format "mm"
If curDay = 8 And myTime >= "18:30" Then ' For night 1st Day of Month
myMonth = Format(curDate - Day(curDate), "mm") 'that keeps format "mm"
Debug.Print myMonth ' format "mm"
Else
Debug.Print myMonth
End If
End Sub
Hi ,Dear Narayan,
I intersting,
For 1st January 2017 "01-01-2017",
If I use myDate = Format(Date -1, "dd-mm-yyyy") 'declared as String
Do I get result "31-12-2016"?
And for myDayMonth = Format(Date -1, "dd-mm"), do i get "31-12"?
Could you please clarify it or may be you have other solution.
Best regards,