VBScript তারিখ ফাংশন এবং VBScript সময় ফাংশন - VBScript টিউটোরিয়াল 6 এবং 7 এর জন্য একটি চমৎকার নির্দেশিকা

VBScript টিউটোরিয়াল – বিষয়বস্তুর সারণী

VBScript টিউটোরিয়াল #1: VBScript ভেরিয়েবলের ওভারভিউ 

VBScript টিউটোরিয়াল #2: VBScript শর্তসাপেক্ষ বিবৃতি এবং লুপ

VBScript টিউটোরিয়াল #3: VBScript পদ্ধতি

VBScript টিউটোরিয়াল #4: VBScript এরর হ্যান্ডলিং এবং এক্সিকিউট VBScript

VBScript টিউটোরিয়াল #5: VBScript স্ট্রিং ফাংশন

VBScript টিউটোরিয়াল #6: VBScript তারিখ ফাংশন

VBScript টিউটোরিয়াল #7: VBScript সময় ফাংশন

VBScript টিউটোরিয়াল #8: VBScript অ্যারে ফাংশন

In this VBScript Tutorial, we are going to learn about the most important and frequently used VBScript Date Functions and VBScript Time Functions, including vbscript Cdate, vbscript DateAdd, vbscript date, vbscript time, vbscript FormatDateTime function, etc. All the vbscript date functions and vbscript time functions are explained with examples.

VBScript টিউটোরিয়াল #6: VBScript তারিখ ফাংশন

While working with dates in vbscript, we can use in-build vbscript date functions to perform important date-related operations such as capture system date, date conversion, extract different parts of a date, calculation, formatting, etc. This article(VBScript Date Functions) contains all the important built-in VBScript date functions, which are mostly used in programs. 

VBScript Date Functions – Summary: 

VBScript Date Functions – Details:

All the important vbscript date functions are explained in this section with a proper example.

vbscript Cdate:

vbscript cdate function used to convert a string expression of a date into date format and returns the converted date value. While updating any date type field such as database field with the date data type, we need to convert the string into date format. Otherwise, an error will be thrown.

বাক্য গঠন: Cdate(date)

প্যারামিটারের বর্ণনা:

তারিখ – It denotes any valid date and time expression in string format. 

উদাহরণ:

In the below example, any valid date expression will be converted into date format using vbscript Cdate function.

strDate = "10-Feb-2021"
dtDate = Cdate(strDate)
‘After the date conversion the variable dtDate will hold the value with date format (#10-Feb-2021#).

vbscript Date:

The vbscript date function returns the present system date.

Syntax: Date

উদাহরণ:

In the below example, we will store the current system date in a variable and display in the message box.

sysDate = Date
msgbox " Current system date is " & sysDate
' OutPut (Msgbox):
' Current system date is 04-Jan-2020

vbscript DateAdd:

vbscript dateadd function returns the calculated date value after adding with specific interval time.

Syntax: DateAdd(interval,number,date)

প্যারামিটারের বর্ণনা:

সংখ্যা – It represents any number we want to add. It can be positive(future date) or negative(past date) value.

তারিখ – It represents any valid date.

অন্তর – It’s a mandatory parameter which denotes the interval of time. The different interval options are –

· yyyy – Represents the quarter interval.

· q – Represents the quarter interval.

· m – Represents the month interval.

· y – Represents the the day of a year interval.

· d – Represents the day interval.

· w – Represents the weekday interval.

· ww – Represents the week of the year interval.

· h – Represents the hour.

· n – Represents the minute.

· s – Represents the second.

উদাহরণ:

In the below example, we will calculate the future date after adding two months with the system date using vbscript dateadd function.

sDate = "04-Jan-2021"
newDate = Cdate(sDate)
newDate = DateAdd("m",+2,sDate)
msgbox "Future date after adding 2 months with " & sDate & " is  " & newDate
vbscript date functions - vbscript DateAdd
vbscript date functions – vbscript DateAdd

vbscript DateDiff:

vbscript datediff function returns the number of an interval between two dates.

Syntax: DateDiff(date1,date2[,firstdayofweek[,firstweekofyear]])

প্যারামিটারের বর্ণনা:

তারিখ 1 – It represents any valid date expression.

তারিখ 2 – It represents any valid date expression.

firstdayofweek – It’s an optional field which denotes the day of the week. The available values are – 

  • 0 = vbUseSystemDayOfWeek (API Setting for National Language Support)
  • 1 = vbSunday (Sunday – default)
  • 2 = vbMonday (Monday)
  • 3 = vbTuesday (Tuesday)
  • 4 = vbWednesday (Wednesday)
  • 5 = vbThursday (Thursday)
  • 6 = vbFriday (Friday)
  • 7 = vbSaturday (Saturday)

firstweekofyear – It’s also an optional field which denotes the first week of the year. The available values are – 

  • 0 = vbUseSystem (API Setting for National Language Support)
  • 1 = vbFirstJan1 (Start with the week when January 1 occurs – default)
  • 2 = vbFirstFourDays (It represent the start week where minimum 4 days are fall in the new year)
  • 3 = vbFirstFullWeek (It represent the week which completely falls in new year)

উদাহরণ:

In the below example, we are calculating the difference in day interval between two consecutive dates using vbscript datediff function.

date1="04-Jan-2021 00:00:00"
date2="05-Jan-2021 23:59:00" 
diff = DateDiff("d", date1, date2)
msgbox "The date difference - " & diff
' OutPut (Msgbox):
' The date difference - 1
vbscript date functions - vbscript DateDiff
vbscript date functions – vbscript DateDiff

vbscript DatePart:

vbscript datediff function returns the specific part(day, month or year) of any particular date.

Syntax: DatePart(interval,date2,firstdayofweek[,firstweekofyear]])

প্যারামিটারের বর্ণনা:

অন্তর – It’s a mandatory parameter which denotes the interval of time. The different interval options are –

· yyyy – Represents the quarter interval.

· q – Represents the quarter interval.

· m – Represents the month interval.

· y – Represents the the day of a year interval.

· d – Represents the day interval.

· w – Represents the weekday interval.

· ww – Represents the week of the year interval.

· h – Represents the hour.

· n – Represents the minute.

· s – Represents the second.

তারিখ – It represents any valid date expression.

firstdayofweek – It’s an optional field which denotes the day of the week. The available values are – 

  • 0 = vbUseSystemDayOfWeek (API Setting for National Language Support)
  • 1 = vbSunday (Sunday – default)
  • 2 = vbMonday (Monday)
  • 3 = vbTuesday (Tuesday)
  • 4 = vbWednesday (Wednesday)
  • 5 = vbThursday (Thursday)
  • 6 = vbFriday (Friday)
  • 7 = vbSaturday (Saturday)

firstweekofyear – It’s also an optional field which denotes the first week of the year. The available values are – 

  • 0 = vbUseSystem (API Setting for National Language Support)
  • 1 = vbFirstJan1 (Start with the week when January 1 occurs – default)
  • 2 = vbFirstFourDays (It represent the start week where minimum 4 days are fall in the new year)
  • 3 = vbFirstFullWeek (It represent the week which completely falls in new year)

উদাহরণ:

Below example evaluates the month part of a given date using vbscript datepart function.

date=Cdate("04-Jan-2021") 
monthPart = DatePart("d", date)
msgbox "The month part - " & monthPart
' OutPut (Msgbox):
' The month part - 1

vbscript IsDate:

vbscript isdate function returns the boolean value as true or false if any string expressing can be converted into date format. Vbscript isdate function is used to test a date expression.

Syntax: Isdate(date)

প্যারামিটারের বর্ণনা:

তারিখ – It denotes any date expression to be verified. 

উদাহরণ:

In the below example, any given test expression is checked for the valid date expression.

date = "04-Jan-2021"
boolResult = IsDate(date)
msgbox "Is Valid date ? Ans: " & monthPart
' OutPut (Msgbox):
' Is Valid date ? Ans: true

vbscript Day:

vbscript day function extracts the number(1-31) that represents the day from a valid date expression.

Syntax: Day(date)

প্যারামিটারের বর্ণনা:

তারিখ – It’s a valid date expression.

উদাহরণ:

In the below example, the day part will be extracted from a given date using vbscript day function.

date = Cdate("04-Jan-2021")
num = Day(date)
msgbox "The day part is - " & num
' OutPut (Msgbox):
' The day part is - 4

vbscript Month:

vbscript month function extracts  the number(1-12) that represents the month from a valid date expression.

বাক্য গঠন: Month(date)

প্যারামিটারের বর্ণনা:

তারিখ – It’s a valid date expression.

উদাহরণ:

In the below example, month will be extracted from a given date using vbscript month function.

date = Cdate("04-Jan-2021")
num = Month(date)
msgbox "The month part is - " & num
' OutPut (Msgbox):
' The month part is - 1

vbscript Year:

vbscript year function extracts the four digit number that represents the year from a valid date expression.

বাক্য গঠন: Year(date)

প্যারামিটারের বর্ণনা:

তারিখ – It’s a valid date expression.

উদাহরণ:

In the below example, the year will be extracted from a given date using vbscript year function.

date = Cdate("04-Jan-2021")
num = year(date)
msgbox "The year part is - " & num
' OutPut (Msgbox):
' The year part is - 2021

vbscript MonthName:

vbscript monthname function returns the name of a specific month code(1-12).

বাক্য গঠন: MonthName(month[,abbreviate])

প্যারামিটারের বর্ণনা:

মাস – It’s representing the code(1-12) for any specific month.

সংক্ষিপ্ত – It’s not an mandatory parameter. It represents to check about the name of the month is abbreviated or not. The default value is false.

উদাহরণ:

month_name = MonthName(12)
msgbox "The month name is - " & month_name
' OutPut (Msgbox):
' The month name is - December

vbscript Weekday:

vbscript weekday function returns the number between 1 and 7 that denotes the day of the particular week.

বাক্য গঠন: WeekDay(date[,firstdayofweek])

প্যারামিটারের বর্ণনা:

তারিখ – It’s a valid date expression.

firstdayofweek – It’s an optional field which denotes the start day of the week. The available values are –

  • 0 = vbUseSystemDayOfWeek (API Setting for National Language Support)
  • 1 = vbSunday (Sunday – default)
  • 2 = vbMonday (Monday)
  • 3 = vbTuesday (Tuesday)
  • 4 = vbWednesday (Wednesday)
  • 5 = vbThursday (Thursday)
  • 6 = vbFriday (Friday)
  • 7 = vbSaturday (Saturday)

উদাহরণ:

In the below example, the day representing the week, will be extracted from a given date using vbscript weekday function.

date = Cdate("06-Jan-2021")
num = Weekday(date,1)
msgbox "The week day is - " & num
' OutPut (Msgbox):
' The week day is - 4

vbscript WeekDayName:

vbscript weekdayname function returns the name of a specific day of a week(1-7).

বাক্য গঠন: WeekDayName(weekday[,abbreviate[,firstdayofweek]])

প্যারামিটারের বর্ণনা:

সপ্তাহের দিন – It’s representing the day code(1-7) for any week.

সংক্ষিপ্ত - It’s not an mandatory parameter. It represents to check about the name of the day is abbreviated or not. The default value is false.

firstdayofweek – It’s an optional field which denotes the start day of the week. The available values are –

  • 0 = vbUseSystemDayOfWeek (API Setting for National Language Support)
  • 1 = vbSunday (Sunday – default)
  • 2 = vbMonday (Monday)
  • 3 = vbTuesday (Tuesday)
  • 4 = vbWednesday (Wednesday)
  • 5 = vbThursday (Thursday)
  • 6 = vbFriday (Friday)
  • 7 = vbSaturday (Saturday)

উদাহরণ:

day_name = WeekdayName(2)
msgbox "The name of the week day - " & day_name
' OutPut (Msgbox):
' The name of the week day - Monday

VBScript টিউটোরিয়াল #7: VBScript সময় ফাংশন

While working with time in vbscript, we can use in-build vbscript time functions to perform important time-related operations such as capture system time, extract different parts of any time, calculation, time formatting, etc. This article(VBScript Time Functions) contains all the important built-in VBScript time functions, which are mostly used in programs. 

Important VBScript Time Functions – Summary: 

VBScript Time Functions – Details:

We will explain all the essential vbscript time functions in this section with a proper example.

vbscript Hour:

vbscript hour function extracts the hour of the day as a number between 0 to 23 from time expression.

Syntax: Hour(time)

প্যারামিটারের বর্ণনা:

সময় – It’s a mandatory parameter that represents a valid time expression.

উদাহরণ:

In the below example, an hour of the day will be extracted from a valid time expression using vbscript hour function.

numHour = Hour("14:40:35")
msgbox "The hour for the day is - " & numHour
' OutPut (Msgbox):
' The hour for the day is - 14

vbscript Minute:

vbscript minute function extracts the minute of the hour as a number between 0 to 59 from time expression.

বাক্য গঠন: Minute(time)

প্যারামিটারের বর্ণনা:

সময় – It’s a mandatory parameter that represents a valid time expression.

উদাহরণ:

In the below example, the minute of the hour will be extracted from a valid time expression using vbscript minute function.

numMin = Minute("14:40:35")
msgbox "The minute for the hour is - " & numMin
' OutPut (Msgbox):
' The minute for the hour is - 40

vbscript Second:

vbscript second function extracts the second of the minute as a number between 0 to 59 from time expression.

বাক্য গঠন: Second(time)

প্যারামিটারের বর্ণনা:

সময় – It’s a mandatory parameter that represents a valid time expression.

উদাহরণ:

In the below example, the second of the minute will be extracted from a valid time expression using vbscript second function.

numSec = Second("14:40:35")
msgbox "The second for the minute is - " & numSec
' OutPut (Msgbox):
' The second for the minute is - 35

vbscript Time:

vbscript time function returns the current system time.

বাক্য গঠন: সময়

উদাহরণ:

In the below example, we will store the current system time in a variable and display in a message box.

sysTime = Time
msgbox " Current system time is " & sysTime
' OutPut (Msgbox):
' Current system time is 14:40:35
vbscript time functions - vbscript Time
vbscript time functions – vbscript Time

vbscript Now:

vbscript now function returns the current system date with timestamp.

বাক্য গঠন: এখন

উদাহরণ:

In the below example, we will store the current system date and time in a variable and display in a message box.

sysTimeStamp = Now
msgbox "Current system date with time is " & sysTimeStamp
' OutPut (Msgbox):
' Current system date with time is 07-Jan-2021 14:40:35

vbscript Timer:

vbscript timer function returns the count of seconds from 12:00 AM.

বাক্য গঠন: সময় নির্ণায়ক

উদাহরণ:

secondCounter = Timer
msgbox "Number of seconds since 12:00 AM  " & secondCounter
' OutPut (Msgbox):
' Number of seconds since 12:00 AM 1067.002

vbscript TimeSerial:

vbscript timeserial method fetch the exact time for a mentioned hour, minute  and second.

Syntax: TimeSerial(hour, minute, second)

প্যারামিটারের বর্ণনা:

ঘন্টা – It’s a mandatory numeric parameter, denotes hours.

মিনিট – It’s a mandatory numeric parameter, denotes minutes.

দ্বিতীয় – It’s a mandatory numeric parameter, denotes seconds.

উদাহরণ:

In the below example, vbscript timeserial function returns the time for the given hours, minutes and seconds.

time = TimeSerial(15,2,20)
msgbox "Specified time is " & time
' OutPut (Msgbox):
' Specified time is 03:02:20 PM

vbscript FormatDateTime:

vbscript formatdatetime function formats and returns a valid and time expression.

Syntax: FormatDateTime(dateExp, format)

প্যারামিটারের বর্ণনা:

dateExp– This is a mandatory parameter. It represents a valid date-time expression.

বিন্যাস – It’s an optional arameter that specifies the date and time format. The available return date and time formats are –

  • 0 = vbGeneralDate – This is the default format value (date format: mm/dd/yyyy and time if specified: hh:mm:ss PM/AM).
  • 1 = vbLongDate (date: weekday, monthname, year)
  • 2 = vbShortDate (date: mm/dd/yyyy)
  • 3 = vbLongTime (time: hh:mm:ss PM/AM)
  • 4 = vbShortTime (Return time: hh:mm)

উদাহরণ:

In the below example, vbscript timeserial function returns the time for the given hours, minutes and seconds.

d=CDate("06-Jan-2021 13:45")
msgbox "Specified formated date time is " & FormatDateTime(d,1)
' OutPut (Msgbox):
' Specified formated date time is Wednesday, Jan 06, 2021
vbscript time functions - vbscript FormatDateTime
vbscript time functions – vbscript FormatDateTime

উপসংহার:

Through this VBScript Date and Time Functions article, we have learned about the learn about the most important and frequently used VBScript Date Functions and VBScript Time functions, including vbscript Cdate, vbscript DateAdd, vbscript FormatDateTime function, etc. We hope this tutorial has helped a lot to brush up on your basics of VB Scripting. If you want to learn more about VBScript, please click এখানে.

মতামত দিন