codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:



Home » ASP » Article

A Better Moustrap: FmtDate to replace FormatDateTime

Article by: Jeremy M (5/15/2004)
Bookmark us now! Add to Favourites
Email a friend!Tell a friend
Summary: An example of a simple-to-use replacement for the visual basic script function FormatDateTime.
Viewed: 32374 times Rating (35 votes): 
 4.3 out of 5
 Rate this Article  Read Comments  Post Comments

A Better Moustrap: FmtDate to replace FormatDateTime



Have you ever been frustrated with the lack of options with visual basic script's built in function FormatDateTime? If so, then this function is for you- and it demonstrates how simple it is to build very complex search-and-relace functions.

Once you've added the two functions below to your ASP or VBS file, you can call the function just like any other function. Two parameters are required, the first is the date/time value you want to re-format, and the second parameter is the format you want. For all the different options you can use in the format, check out the comments at the top of FmtDate.

I'm not the original author of this function, but I've added and changed a lot of it to make it more useful. I've used it and modified so much for so many years, I don't even know where the original version came from.

Here it is, have fun!

example:

Select All Code


returns

Select All Code


Here's the function(s). You need both for it to work properly! FmtDate calls

Select All Code







CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'A Better Moustrap: FmtDate to replace FormatDateTime'
Posted by :  gmason at 17:17 on Wednesday, January 17, 2007
Tried to put comments in here twice without sucess.

<Added>

Of course now it works.
Briefly recapping:
Nice func solved alot of problems for me and I will reuse frequently.

Made 2 changes to %d and %m to make sure it returned a 2 position value for month and date numbers (obviously I am no longer returning integers)

G Mason
www.thegreenhorse.com


To post comments you need to become a member. If you are already a member, please log in .

 



RELATED ARTICLES
ASP FilesystemObject
by Jeff Anderson
An introduction to the Filesystemobject
ASP GetTempName
by Jeff Anderson
Use the GetTempName method to create a randomly generated temporary file on the server.
ASP OpenTextFile
by Jeff Anderson
An introduction to the OpenTextFile Method of the FileSystemObject
ASP Format Date and Time Script
by Jeff Anderson
An ASP script showing the variety of date and time formats possible using the FormatDateTime Function.
Email validation using Regular Expression
by Jeff Anderson
Using regular expression syntax is an exellent way to thoroughly validate an email. It's possible in ASP.
ASP FileExists
by Jeff Anderson
An introduction to the FileExistsMethod of the FileSystemObject
Creating a Dynamic Reports using ASP and Excel
by Jeff Anderson
A simple way to generate Excel reports from a database using Excel.
Concatenate strings in sql
by Jeff Anderson
A brief introduction to concatenating strings in an sql query (using SQL server or access databases).
Add or Subtract Hours in SQL or ASP using DateAdd
by Jeff Anderson
A beginners guide to using the SQL DATEADD function to add or subtract hours. Particularly useful when setting the time displayed on the ASP page to a different time zone (eg when the server is in the US, and the site is for a UK audience).
ASP CreateTextFile
by Jeff Anderson
An explanation of the CreateTextFile Method, part of the ASP FileSystemObject








Recent Forum Threads
• C++
• Re: refresh parent after closing pop up window
• Dynamic Insertion
• Date and Time function around the world???
• Significant Factors
• Perl array access
• Re: huffman encoding and decoding in C++...
• Perl One Liner: Replace {(
• Re: html including php, accessing the functions


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009