techpreparation-homepage

Home  Interview Questions  Aptitude Questions  Tutorials  Placement Papers  Search  Resume Guide  Soft Skills  Video  Forum  Blog


Technical Interview Questions

Visual Basic Interview Question
.NET Web Interview Questions
.NET Interview Questions
C# Interview Questions
                              .........More

Source Codes
Asp .NET Source Codes
Asp VB Script Source Codes
                              .........More

Soft Skills
Communication Skills
Leadership Skills
                              .........More

Subscribe to our Newsletters
Name:
Email:

 

 

  

Asp/VB Script Source Codes

Date Format

Date formats
Date Parts
Date Add and Subtract
Date Difference
Is this year a Leap year
How to calculate Julian Date
Date countdown till a given date
First and Last day of Month


Date Format [ Relative to the date as 2/7/2000 10:37:48 AM ]


<%=FormatDateTime(Now(),1) %>
Outputs as : Monday, February 07, 2000


<%=FormatDateTime(Now(),2)%>
Outputs as : 2/7/2000


<%=Now%>
Outputs as : 2/7/2000 10:24:57 AM



Date Part [ Relative to the date 2/7/2000 10:37:48 AM ]

Day

Today is <%=Day(Date)%>
Outputs as : Today is 7

Week

This is week # <%= DatePart("ww",date)%> of the this year
Outputs as : This is week # 7 of this year


This is weekday <%= WeekDay(Date)%> of this year
Outputs as : This is weekday 2 of this year


Today is <%=WeekDayName(WeekDay(Date))%>
Outputs as : Today is Monday


Month


The month Now is <%=Month(Date)%>
Outputs : The month Now is 2



Another way, of saying the current month is <%=(DatePart("m",date))%>
Outputs : Another way, of saying the current month is 2



The MonthName is <%=MonthName(Month(Date))%>
Outputs : The MonthName is February


Year

The year is <%=Year(Date)%>
Outputs : The year is 2000







Date Add and Subtract


Add

Day

2 Days from 2/9/2000 it will be <%=DateAdd("d",2,CDate("2/9/2000"))%>
Outputs : 2 Days from now it will be 2/11/2000

Month

2 Months from 2/9/2000 it will be <%=DateAdd("m",2,CDate("2/9/2000"))%>
Outputs : 2 Months from 2/9/2000 it will be 4/9/2000

Year

2 Years from 2/9/2000 it will be <%=DateAdd("yyyy",2,CDate("2/9/2000"))%>
Outputs : 2 Years from 2/9/2000 it will be 2/9/2002


Subtract


Day

2 Days back from 2/9/2000 it was <%=DateAdd("d",-2,CDate("2/9/2000"))%>
Outputs : 2 Days back from now it was be 2/7/2000

Month

2 Months back from 2/9/2000 it was be <%=DateAdd("m",-2,CDate("2/9/2000"))%>
Outputs : 2 Months back from 2/9/2000 it was 12/9/1999

Year

2 Years from 2/9/2000 it will be <%=DateAdd("yyyy",-2,CDate("2/9/2000"))%>
Outputs : 2 Years back from 2/9/2000 it was 2/9/1998




Date Difference [ Relative Date : 2/7/2000 ]

Day

Its <%=DateDiff("d","2/7/2000","8/15/1947")*-1 %> days between '8/15/1947' and '2/7/2000'
Outputs : Its 19169 days between '8/15/1947' and '2/7/2000'

Week

Its <%=DateDiff("ww","2/7/2000","8/15/1947")*-1 %> weeks between '8/15/1947' and '2/7/2000'
Outputs : Its 2739 weeks between '8/15/1947' and '2/7/2000'

Month

Its <%=DateDiff("m","2/7/2000","8/15/1947")*-1 %> months between '8/15/1947' and '2/7/2000'
Outputs : Its 630 months between '8/15/1947' and '2/7/2000'

Quarter

Its <%=DateDiff("q","2/7/2000","8/15/1947")*-1 %> quarters between '8/15/1947' and '2/7/2000'
Outputs : Its 210 Quarters between '8/15/1947' and '2/7/2000'

Year

Its <%=DateDiff("yyyy","2/7/2000","8/15/1947")*-1 %> years between '8/15/1947' and '2/7/2000'
Outputs : Its 53 between '8/15/1947' and '2/7/2000'




Leap Year

<%
Dim lYear
lYear = Year(CDate("2/9/2000"))
leap_yes = "is a leap year"
leap_no = "is not a leap year"
If (lYear mod 4 = 0) AND ((lYear mod 1 0) OR (lYear mod 4 = 0)) then
' It is a Leap Year
Response.Write lYear & " " & leap_yes
else
' it is not a leap year
Response.Write lYear & " " & leap_no
End if
%gt;
Outputs : 2000 is a leap year




Julian Date

<%
d0=DateSerial ("2000", "1", "1")
d1=Date - d0 + 1
Response.write "Today's Julian Date Is #" & d1
%>
Outputs : Today's Julian Date Is #38



Date Countdown

<%
dim strDateTime
strDateTime = CDate("2/9/2000")
strFutureDay = #12/31#
Response.write "There are" & INT(strFutureDay - strDateTime) & " more days till December 31st."
%>
Outputs : There are 327 more days till December 31st.




How to find first and last day of the month

Calculate first date of current month

<%
BaseDate = CDate("2/9/2000")
FirstOfMonth = DateSerial(Year(BaseDate), Month(BaseDate) + iOffset, 1)
Response.write "The first date of this month is " & FirstOfMonth
%>
Outputs : The first date of this month is 2/1/2000


Calculate last date of current month

<%
BaseDate = CDate("2/9/2000")
EndOfMonth = DateSerial(Year(BaseDate), Month(BaseDate) + 1, 0)
Response.write "The last date of this month is " & EndOfMonth
%>
Outputs : The last date of this month is 2/29/2000


<<<----- Return to Asp/VB Script Source Code Questions Page.


Have a Question ? post your questions here. It will be answered as soon as possible.

Check Microsoft .Net Interview Questions for more Microsoft .Net Interview Questions with Answers.

Check .Net Database Interview Questions for more .Net Database Interview Questions with answers

Check Job Interview Questions for more Interview Questions with Answers