Presentation is loading. Please wait.

Presentation is loading. Please wait.

ASP Date and Time Function List It's important to test that your data is valid before you work with it. These variable testing functions do the trick!

Similar presentations


Presentation on theme: "ASP Date and Time Function List It's important to test that your data is valid before you work with it. These variable testing functions do the trick!"— Presentation transcript:

1 ASP Date and Time Function List It's important to test that your data is valid before you work with it. These variable testing functions do the trick!

2 Date This function simply returns to you the current date, according to your computer's system clock. The ASP function called Date is very simple - it returns back to you the current system date. You simply call the Date() function, you will know the date that your system clock has for you. You can do: CurrDate = Date() Note that this does not include time - the Now() function includes the time component.

3 Now This function gives you the full date and time according to the web server. The ASP function called Now is very simple - it returns back to you the current system date and time. You simply call the Now() function and voila, you know the date and time that your system clock has for you. You can do: CurrDateTime = Now() Note that if you don't care about the time part, the Date() function returns just the date.

4 Getting Parts of a Given Date Second This function gives you the second value (0 to 59) of the current date/time. Minute This function gives you the minute (0 to 59) of a given date/time. Hour This function gives you the military time (0 to 23) a given date/time is. Day This function lets you know what day (from 1 to 31) a given date is. The Day function in ASP lets you find out what day in the current month it is. If the current date is January 3, then the Day function will return 3. So, for example if you have a StartDate variable and want to extract just the day part, you would say StartDay = Day(StartDate) StartDay would then be equal to the value 3. Make sure, of course, that StartDate is actually a date value :)

5 Getting Parts of a Given Date Weekday This function gives you a number (0 to 6) representing the current weekday. Month This function gives you the month (1 to 12) of a given date/time. Year This function gives you the year part of the date/time.

6 Getting the Name of a Date Part WeekdayName This function gives you the name of the week. To add nice, customized messages in your newsletters, website or other net uses, the WeekdayName lets you figure out the name - Sunday, Monday, etc. - of any date. Note that the function WeekdayName does NOT work directly on a raw date. You cannot say WeekdayName(Now()) for example. Instead, you must feed WeekdayName the *id number* of the day of the week. So for Sunday you feed it 0, for Monday you feed it 1, and so on. You figure out the weeday ID number by using the Weekday function. For example, if you want to say the word "Saturday" on your website when it's a Saturday, you would use currdate = now() currid = weekday(currdate) currname = weekdayname(currid) response.write "today is" & currname

7 Getting the Name of a Date Part MonthName This function returns the actual name of the month of a given date/time. If you've got a date and want to display the real world name of that month to display, the monthname function is what you want. This function does NOT take in a full date - it takes in the month's ID number. So January is 1, February is 2, and so on. You can easily get the month number from a date using the Month function. So your code might look something like this - CurrDate = Now() CurrMonthID = Month(CurrDate) CurrMonthName = MonthName(CurrMonthID) response.write "It is the lovely month of " & CurrMonthName

8 Date Calculations DateAdd The DateAdd functon lets you add a certain amount of time to any date. You can determine what will be a week from now, what was 3 days ago, or any other difference. The format of the DateAdd function is DateAdd(code, count, date) Code comes from the table and indicates what unit of time you are adding to your initial date: - Count is the number of those units you will be adding - 3 days, 4 hours, 1 month. This can be negative if you want to go backwards in time. Date is the starting date you wish to begin with. So to take today's date and figure out what the date was one month ago, you would use DateAdd("m", -1, Now())

9 DateDiff Looking to determine how much time has elapsed between two dates? This function will let you know. With DateDiff, you can determine the difference between two dates. This lets you see how long it's been since someone last logged in and much more. The format of the DateDiff function is DateDiff(code, date1, date2) Code comes from the table and indicates what unit of time you are wanting the difference measured in: The two dates are the dates which you will be comparing to each other So to take today's date, a "Last Logon" date and see how many days it's been since your user logged onto your site, you would use: DateDiff("d", LastLogon, Now())


Download ppt "ASP Date and Time Function List It's important to test that your data is valid before you work with it. These variable testing functions do the trick!"

Similar presentations


Ads by Google