Balaramesht's Blog


DateTimeFormatInfo Class

Defines how DateTime values are formatted and displayed, depending on the culture.

For a list of all members of this type, see DateTimeFormatInfo Members.

System.Object
   System.Globalization.DateTimeFormatInfo

[Visual Basic]
<Serializable>
NotInheritable Public Class DateTimeFormatInfo
   Implements ICloneable, IFormatProvider
[C#]
[Serializable]
public sealed class DateTimeFormatInfo : ICloneable,
   IFormatProvider
[C++]
[Serializable]
public __gc __sealed class DateTimeFormatInfo : public ICloneable,
   IFormatProvider
[JScript]
public
   Serializable
class DateTimeFormatInfo implements ICloneable,
   IFormatProvider

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

This class contains information, such as date patterns, time patterns, and AM/PM designators.

To create a DateTimeFormatInfo for a specific culture, create a CultureInfo for that culture and retrieve the CultureInfo.DateTimeFormat property. To create a DateTimeFormatInfo for the culture of the current thread, use the CurrentInfo property. To create a DateTimeFormatInfo for the invariant culture, use the InvariantInfo property for a read-only version, or use the DateTimeFormatInfo constructor for a writable version. It is not possible to create a DateTimeFormatInfo for a neutral culture.

The user might choose to override some of the values associated with the current culture of Windows through Regional and Language Options (or Regional Options or Regional Settings) in Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. If the CultureInfo.UseUserOverride property is set to true, the properties of the CultureInfo.DateTimeFormat instance, the CultureInfo.NumberFormat instance, and the CultureInfo.TextInfo instance are also retrieved from the user settings. If the user settings are incompatible with the culture associated with the CultureInfo (for example, if the selected calendar is not one of the OptionalCalendars), the results of the methods and the values of the properties are undefined.

DateTime values are formatted using standard or custom patterns stored in the properties of a DateTimeFormatInfo.

The standard patterns can be replaced with custom patterns by setting the associated properties of a writable DateTimeFormatInfo. To determine if a DateTimeFormatInfo is writable, use the IsReadOnly property.

The following table lists the standard format characters for each standard pattern and the associated DateTimeFormatInfo property that can be set to modify the standard pattern. The format characters are case-sensitive; for example, ‘g’ and ‘G’ represent slightly different patterns.

Format Character Associated Property/ Description
d ShortDatePattern
D LongDatePattern
f Full date and time (long date and short time)
F FullDateTimePattern (long date and long time)
g General (short date and short time)
G General (short date and long time)
m, M MonthDayPattern
r, R RFC1123Pattern
s SortableDateTimePattern (based on ISO 8601) using local time
t ShortTimePattern
T LongTimePattern
u UniversalSortableDateTimePattern using the format for universal time display
U Full date and time (long date and long time) using universal time
y, Y YearMonthPattern

The following table lists the patterns that can be combined to construct custom patterns. The patterns are case-sensitive; for example, “MM” is recognized, but “mm” is not. If the custom pattern contains white-space characters or characters enclosed in single quotation marks, the output string will also contain those characters. Characters not defined as part of a format pattern or as format characters are reproduced literally.

Format Pattern Description
d The day of the month. Single-digit days will not have a leading zero.
dd The day of the month. Single-digit days will have a leading zero.
ddd The abbreviated name of the day of the week, as defined in AbbreviatedDayNames.
dddd The full name of the day of the week, as defined in DayNames.
M The numeric month. Single-digit months will not have a leading zero.
MM The numeric month. Single-digit months will have a leading zero.
MMM The abbreviated name of the month, as defined in AbbreviatedMonthNames.
MMMM The full name of the month, as defined in MonthNames.
y The year without the century. If the year without the century is less than 10, the year is displayed with no leading zero.
yy The year without the century. If the year without the century is less than 10, the year is displayed with a leading zero.
yyyy The year in four digits, including the century.
gg The period or era. This pattern is ignored if the date to be formatted does not have an associated period or era string.
h The hour in a 12-hour clock. Single-digit hours will not have a leading zero.
hh The hour in a 12-hour clock. Single-digit hours will have a leading zero.
H The hour in a 24-hour clock. Single-digit hours will not have a leading zero.
HH The hour in a 24-hour clock. Single-digit hours will have a leading zero.
m The minute. Single-digit minutes will not have a leading zero.
mm The minute. Single-digit minutes will have a leading zero.
s The second. Single-digit seconds will not have a leading zero.
ss The second. Single-digit seconds will have a leading zero.
f The fraction of a second in single-digit precision. The remaining digits are truncated.
ff The fraction of a second in double-digit precision. The remaining digits are truncated.
fff The fraction of a second in three-digit precision. The remaining digits are truncated.
ffff The fraction of a second in four-digit precision. The remaining digits are truncated.
fffff The fraction of a second in five-digit precision. The remaining digits are truncated.
ffffff The fraction of a second in six-digit precision. The remaining digits are truncated.
fffffff The fraction of a second in seven-digit precision. The remaining digits are truncated.
t The first character in the AM/PM designator defined in AMDesignator or PMDesignator, if any.
tt The AM/PM designator defined in AMDesignator or PMDesignator, if any.
z The time zone offset (“+” or “-” followed by the hour only). Single-digit hours will not have a leading zero. For example, Pacific Standard Time is “-8″.
zz The time zone offset (“+” or “-” followed by the hour only). Single-digit hours will have a leading zero. For example, Pacific Standard Time is “-08″.
zzz The full time zone offset (“+” or “-” followed by the hour and minutes). Single-digit hours and minutes will have leading zeros. For example, Pacific Standard Time is “-08:00″.
: The default time separator defined in TimeSeparator.
/ The default date separator defined in DateSeparator.
% c Where c is a format pattern if used alone. The “%” character can be omitted if the format pattern is combined with literal characters or other format patterns.
\ c Where c is any character. Displays the character literally. To display the backslash character, use “\\”.

Only format patterns listed in the second table above can be used to create custom patterns; standard format characters listed in the first table cannot be used to create custom patterns. Custom patterns are at least two characters long; for example,

  • DateTime.ToString( “d”) returns the DateTime value; “d” is the standard short date pattern.
  • DateTime.ToString( “%d”) returns the day of the month; “%d” is a custom pattern.
  • DateTime.ToString( “d “) returns the day of the month followed by a white-space character; “d ” is a custom pattern.

A DateTimeFormatInfo or a NumberFormatInfo can be created only for the invariant culture or for specific cultures, not for neutral cultures. For more information about the invariant culture, specific cultures, and neutral cultures, see the CultureInfo class.

This class implements the ICloneable interface to enable duplication of DateTimeFormatInfo objects. It also implements IFormatProvider to supply formatting information to applications.

Example

[Visual Basic, C#, C++] The following code example prints out the different format patterns for the en-US culture using the format characters. It also displays the value of the properties associated with the format character.

[Visual Basic]
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Public Class SamplesDTFI

   Public Shared Sub Main()

      ' Creates and initializes a DateTimeFormatInfo associated with the en-US culture.
      Dim myDTFI As DateTimeFormatInfo = New CultureInfo("en-US", False).DateTimeFormat

      ' Creates a DateTime with the Gregorian date January 3, 2002 (year=2002, month=1, day=3).
      ' The Gregorian calendar is the default calendar for the en-US culture.
      Dim myDT As New DateTime(2002, 1, 3)

      ' Displays the format pattern associated with each format character.
      Console.WriteLine("FORMAT  en-US EXAMPLE")
      Console.WriteLine("CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY")
      Console.WriteLine()
      Console.WriteLine("  d     {0}", myDT.ToString("d"))
      Console.WriteLine("        {0} {1}", myDTFI.ShortDatePattern, "(ShortDatePattern)")
      Console.WriteLine()
      Console.WriteLine("  D     {0}", myDT.ToString("D"))
      Console.WriteLine("        {0} {1}", myDTFI.LongDatePattern, "(LongDatePattern)")
      Console.WriteLine()
      Console.WriteLine("  f     {0}", myDT.ToString("f"))
      Console.WriteLine()
      Console.WriteLine("  F     {0}", myDT.ToString("F"))
      Console.WriteLine("        {0} {1}", myDTFI.FullDateTimePattern, "(FullDateTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  g     {0}", myDT.ToString("g"))
      Console.WriteLine()
      Console.WriteLine("  G     {0}", myDT.ToString("G"))
      Console.WriteLine()
      Console.WriteLine("  m     {0}", myDT.ToString("m"))
      Console.WriteLine("        {0} {1}", myDTFI.MonthDayPattern, "(MonthDayPattern)")
      Console.WriteLine()
      Console.WriteLine("  M     {0}", myDT.ToString("M"))
      Console.WriteLine("        {0} {1}", myDTFI.MonthDayPattern, "(MonthDayPattern)")
      Console.WriteLine()
      Console.WriteLine("  r     {0}", myDT.ToString("r"))
      Console.WriteLine("        {0} {1}", myDTFI.RFC1123Pattern, "(RFC1123Pattern)")
      Console.WriteLine()
      Console.WriteLine("  R     {0}", myDT.ToString("R"))
      Console.WriteLine("        {0} {1}", myDTFI.RFC1123Pattern, "(RFC1123Pattern)")
      Console.WriteLine()
      Console.WriteLine("  s     {0}", myDT.ToString("s"))
      Console.WriteLine("        {0} {1}", myDTFI.SortableDateTimePattern, "(SortableDateTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  t     {0}", myDT.ToString("t"))
      Console.WriteLine("        {0} {1}", myDTFI.ShortTimePattern, "(ShortTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  T     {0}", myDT.ToString("T"))
      Console.WriteLine("        {0} {1}", myDTFI.LongTimePattern, "(LongTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  u     {0}", myDT.ToString("u"))
      Console.WriteLine("        {0} {1}", myDTFI.UniversalSortableDateTimePattern, "(UniversalSortableDateTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  U     {0}", myDT.ToString("U"))
      Console.WriteLine()
      Console.WriteLine("  y     {0}", myDT.ToString("y"))
      Console.WriteLine("        {0} {1}", myDTFI.YearMonthPattern, "(YearMonthPattern)")
      Console.WriteLine()
      Console.WriteLine("  Y     {0}", myDT.ToString("Y"))
      Console.WriteLine("        {0} {1}", myDTFI.YearMonthPattern, "(YearMonthPattern)")

   End Sub 'Main 

End Class 'SamplesDTFI

'This code produces the following output.
'
'FORMAT  en-US EXAMPLE
'CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY
'
'  d     1/3/2002
'        M/d/yyyy (ShortDatePattern)
'
'  D     Thursday, January 03, 2002
'        dddd, MMMM dd, yyyy (LongDatePattern)
'
'  f     Thursday, January 03, 2002 12:00 AM
'
'  F     Thursday, January 03, 2002 12:00:00 AM
'        dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)
'
'  g     1/3/2002 12:00 AM
'
'  G     1/3/2002 12:00:00 AM
'
'  m     January 03
'        MMMM dd (MonthDayPattern)
'
'  M     January 03
'        MMMM dd (MonthDayPattern)
'
'  r     Thu, 03 Jan 2002 00:00:00 GMT
'        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)
'
'  R     Thu, 03 Jan 2002 00:00:00 GMT
'        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)
'
'  s     2002-01-03T00:00:00
'        yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)
'
'  t     12:00 AM
'        h:mm tt (ShortTimePattern)
'
'  T     12:00:00 AM
'        h:mm:ss tt (LongTimePattern)
'
'  u     2002-01-03 00:00:00Z
'        yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)
'
'  U     Thursday, January 03, 2002 8:00:00 AM
'
'  y     January, 2002
'        MMMM, yyyy (YearMonthPattern)
'
'  Y     January, 2002
'        MMMM, yyyy (YearMonthPattern)
'

[C#]
using System;
using System.Globalization;

public class SamplesDTFI  {

   public static void Main()  {

      // Creates and initializes a DateTimeFormatInfo associated with the en-US culture.
      DateTimeFormatInfo myDTFI = new CultureInfo( "en-US", false ).DateTimeFormat;

      // Creates a DateTime with the Gregorian date January 3, 2002 (year=2002, month=1, day=3).
      // The Gregorian calendar is the default calendar for the en-US culture.
      DateTime myDT = new DateTime( 2002, 1, 3 );

      // Displays the format pattern associated with each format character.
      Console.WriteLine( "FORMAT  en-US EXAMPLE" );
      Console.WriteLine( "CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY\n" );
      Console.WriteLine( "  d     {0}", myDT.ToString("d") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.ShortDatePattern, "(ShortDatePattern)" );
      Console.WriteLine( "  D     {0}", myDT.ToString("D") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.LongDatePattern, "(LongDatePattern)" );
      Console.WriteLine( "  f     {0}\n", myDT.ToString("f") );
      Console.WriteLine( "  F     {0}", myDT.ToString("F") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.FullDateTimePattern, "(FullDateTimePattern)" );
      Console.WriteLine( "  g     {0}\n", myDT.ToString("g") );
      Console.WriteLine( "  G     {0}\n", myDT.ToString("G") );
      Console.WriteLine( "  m     {0}", myDT.ToString("m") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.MonthDayPattern, "(MonthDayPattern)" );
      Console.WriteLine( "  M     {0}", myDT.ToString("M") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.MonthDayPattern, "(MonthDayPattern)" );
      Console.WriteLine( "  r     {0}", myDT.ToString("r") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.RFC1123Pattern, "(RFC1123Pattern)" );
      Console.WriteLine( "  R     {0}", myDT.ToString("R") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.RFC1123Pattern, "(RFC1123Pattern)" );
      Console.WriteLine( "  s     {0}", myDT.ToString("s") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.SortableDateTimePattern, "(SortableDateTimePattern)" );
      Console.WriteLine( "  t     {0}", myDT.ToString("t") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.ShortTimePattern, "(ShortTimePattern)" );
      Console.WriteLine( "  T     {0}", myDT.ToString("T") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.LongTimePattern, "(LongTimePattern)" );
      Console.WriteLine( "  u     {0}", myDT.ToString("u") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.UniversalSortableDateTimePattern, "(UniversalSortableDateTimePattern)" );
      Console.WriteLine( "  U     {0}\n", myDT.ToString("U") );
      Console.WriteLine( "  y     {0}", myDT.ToString("y") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.YearMonthPattern, "(YearMonthPattern)" );
      Console.WriteLine( "  Y     {0}", myDT.ToString("Y") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.YearMonthPattern, "(YearMonthPattern)" );

   }

}

/*
This code produces the following output.

FORMAT  en-US EXAMPLE
CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY

  d     1/3/2002
        M/d/yyyy (ShortDatePattern)

  D     Thursday, January 03, 2002
        dddd, MMMM dd, yyyy (LongDatePattern)

  f     Thursday, January 03, 2002 12:00 AM

  F     Thursday, January 03, 2002 12:00:00 AM
        dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)

  g     1/3/2002 12:00 AM

  G     1/3/2002 12:00:00 AM

  m     January 03
        MMMM dd (MonthDayPattern)

  M     January 03
        MMMM dd (MonthDayPattern)

  r     Thu, 03 Jan 2002 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  R     Thu, 03 Jan 2002 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  s     2002-01-03T00:00:00
        yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)

  t     12:00 AM
        h:mm tt (ShortTimePattern)

  T     12:00:00 AM
        h:mm:ss tt (LongTimePattern)

  u     2002-01-03 00:00:00Z
        yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)

  U     Thursday, January 03, 2002 8:00:00 AM

  y     January, 2002
        MMMM, yyyy (YearMonthPattern)

  Y     January, 2002
        MMMM, yyyy (YearMonthPattern)

*/

[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;

int main()
{
   // Creates and initializes a DateTimeFormatInfo associated with the en-US culture.
   CultureInfo * MyCI = new CultureInfo(S"en-US", false);
   DateTimeFormatInfo* myDTFI = MyCI -> DateTimeFormat;

   // Creates a DateTime with the Gregorian date January 3, 2002 (year=2002, month=1, day=3).
   // The Gregorian calendar is the default calendar for the en-US culture.
   DateTime myDT = DateTime(2002, 1, 3);

   // Displays the format pattern associated with each format character.
   Console::WriteLine(S"FORMAT  en-US EXAMPLE");
   Console::WriteLine(S"CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY\n");
   Console::WriteLine(S"  d {0}", myDT.ToString(S"d"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> ShortDatePattern, S"(ShortDatePattern)");
   Console::WriteLine(S"  D {0}", myDT.ToString(S"D"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> LongDatePattern, S"(LongDatePattern)");
   Console::WriteLine(S"  f {0}\n", myDT.ToString(S"f"));
   Console::WriteLine(S"  F {0}", myDT.ToString(S"F"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> FullDateTimePattern, S"(FullDateTimePattern)");
   Console::WriteLine(S"  g {0}\n", myDT.ToString(S"g"));
   Console::WriteLine(S"  G {0}\n", myDT.ToString(S"G"));
   Console::WriteLine(S"  m {0}", myDT.ToString(S"m"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> MonthDayPattern, S"(MonthDayPattern)");
   Console::WriteLine(S"  M {0}", myDT.ToString(S"M"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> MonthDayPattern, S"(MonthDayPattern)");
   Console::WriteLine(S"  r {0}", myDT.ToString(S"r"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> RFC1123Pattern, S"(RFC1123Pattern)");
   Console::WriteLine(S"  R {0}", myDT.ToString(S"R"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> RFC1123Pattern, S"(RFC1123Pattern)");
   Console::WriteLine(S"  s {0}", myDT.ToString(S"s"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> SortableDateTimePattern, S"(SortableDateTimePattern)");
   Console::WriteLine(S"  t {0}", myDT.ToString(S"t"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> ShortTimePattern, S"(ShortTimePattern)");
   Console::WriteLine(S"  T {0}", myDT.ToString(S"T"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> LongTimePattern, S"(LongTimePattern)");
   Console::WriteLine(S"  u {0}", myDT.ToString(S"u"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> UniversalSortableDateTimePattern, S"(UniversalSortableDateTimePattern)");
   Console::WriteLine(S"  U {0}\n", myDT.ToString(S"U"));
   Console::WriteLine(S"  y {0}", myDT.ToString(S"y"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> YearMonthPattern, S"(YearMonthPattern)");
   Console::WriteLine(S"  Y {0}", myDT.ToString(S"Y"));
   Console::WriteLine(S" {0} {1}\n", myDTFI -> YearMonthPattern, S"(YearMonthPattern)");
}

/*
This code produces the following output.

FORMAT  en-US EXAMPLE
CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY

d     1/3/2002
M/d/yyyy (ShortDatePattern)

D     Thursday, January 03, 2002
dddd, MMMM dd, yyyy (LongDatePattern)

f     Thursday, January 03, 2002 12:00 AM

F     Thursday, January 03, 2002 12:00:00 AM
dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)

g     1/3/2002 12:00 AM

G     1/3/2002 12:00:00 AM

m     January 03
MMMM dd (MonthDayPattern)

M     January 03
MMMM dd (MonthDayPattern)

r     Thu, 03 Jan 2002 00:00:00 GMT
ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

R     Thu, 03 Jan 2002 00:00:00 GMT
ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

s     2002-01-03T00:00:00
yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)

t     12:00 AM
h:mm tt (ShortTimePattern)

T     12:00:00 AM
h:mm:ss tt (LongTimePattern)

u     2002-01-03 00:00:00Z
yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)

U     Thursday, January 03, 2002 8:00:00 AM

y     January, 2002
MMMM, yyyy (YearMonthPattern)

Y     January, 2002
MMMM, yyyy (YearMonthPattern)

*/

create and maintain robots.txt for a website

About /robots.txt

In a nutshell

Web site owners use the /robots.txt file to give instructions about their site to web robots; this is called The Robots Exclusion Protocol.

It works likes this: a robot wants to vists a Web site URL, say http://www.example.com/welcome.html. Before it does so, it firsts checks for http://www.example.com/robots.txt, and finds:

User-agent: *
Disallow: /

The “User-agent: *” means this section applies to all robots. The “Disallow: /” tells the robot that it should not visit any pages on the site.

There are two important considerations when using /robots.txt:

  • robots can ignore your /robots.txt. Especially malware robots that scan the web for security vulnerabilities, and email address harvesters used by spammers will pay no attention.
  • the /robots.txt file is a publicly available file. Anyone can see what sections of your server you don’t want robots to use.

So don’t try to use /robots.txt to hide information.

See also:

The details

The /robots.txt is a de-facto standard, and is not owned by any standards body. There are two historical descriptions:

In addition there are external resources:

The /robots.txt standard is not actively developed. See What about further development of /robots.txt? for more discussion.

The rest of this page gives an overview of how to use /robots.txt on your server, with some simple recipes. To learn more see also the FAQ.

How to create a /robots.txt file

Where to put it

The short answer: in the top-level directory of your web server.

The longer answer:

When a robot looks for the “/robots.txt” file for URL, it strips the path component from the URL (everything from the first single slash), and puts “/robots.txt” in its place.

For example, for “http://www.example.com/shop/index.html, it will remove the “/shop/index.html“, and replace it with “/robots.txt“, and will end up with “http://www.example.com/robots.txt”.

So, as a web site owner you need to put it in the right place on your web server for that resulting URL to work. Usually that is the same place where you put your web site’s main “index.html” welcome page. Where exactly that is, and how to put the file there, depends on your web server software.

Remember to use all lower case for the filename: “robots.txt“, not “Robots.TXT.

See also:

What to put in it

The “/robots.txt” file is a text file, with one or more records. Usually contains a single record looking like this:

User-agent: *
Disallow: /cgi-bin/
Disallow: /tmp/
Disallow: /~joe/

In this example, three directories are excluded.

Note that you need a separate “Disallow” line for every URL prefix you want to exclude — you cannot say “Disallow: /cgi-bin/ /tmp/” on a single line. Also, you may not have blank lines in a record, as they are used to delimit multiple records.

Note also that globbing and regular expression are not supported in either the User-agent or Disallow lines. The ‘*’ in the User-agent field is a special value meaning “any robot”. Specifically, you cannot have lines like “User-agent: *bot*”, “Disallow: /tmp/*” or “Disallow: *.gif”.

What you want to exclude depends on your server. Everything not explicitly disallowed is considered fair game to retrieve. Here follow some examples:

To exclude all robots from the entire server
User-agent: *
Disallow: /
To allow all robots complete access
User-agent: *
Disallow:

(or just create an empty “/robots.txt” file, or don’t use one at all)

To exclude all robots from part of the server
User-agent: *
Disallow: /cgi-bin/
Disallow: /tmp/
Disallow: /junk/
To exclude a single robot
User-agent: BadBot
Disallow: /
To allow a single robot
User-agent: Google
Disallow:

User-agent: *
Disallow: /
To exclude all files except one

This is currently a bit awkward, as there is no “Allow” field. The easy way is to put all files to be disallowed into a separate directory, say “stuff”, and leave the one file in the level above this directory:

User-agent: *
Disallow: /~joe/stuff/

Alternatively you can explicitly disallow all disallowed pages:

User-agent: *
Disallow: /~joe/junk.html
Disallow: /~joe/foo.html
Disallow: /~joe/bar.html

Examples

This example allows all robots to visit all files because the wildcard "*" specifies all robots:

User-agent: *

Disallow:

This example keeps all robots out:

User-agent: *

Disallow: /

The next is an example that tells all crawlers not to enter four directories of a website:

User-agent: *

Disallow: /cgi-bin/

Disallow: /images/

Disallow: /tmp/

Disallow: /private/

Example that tells a specific crawler not to enter one specific directory:

User-agent: BadBot # replace the 'BadBot' with the actual user-agent of the bot

Disallow: /private/

Example that tells all crawlers not to enter one specific file:

User-agent: *

Disallow: /directory/file.html

Note that all other files in the specified directory will be processed.

Example demonstrating how comments can be used:

# Comments appear after the "#" symbol at the start of a line, or after a directive

User-agent: * # match all bots

Disallow: / # keep them out

[edit] Nonstandard extensions

[edit] Crawl-delay directive

Several major crawlers support a Crawl-delay parameter, set to the number of seconds to wait between successive requests to the same server: [1] [2]

User-agent: *

Crawl-delay: 10

[edit] Allow directive

Some major crawlers support an Allow directive which can counteract a following Disallow directive.[3] [4] This is useful when you disallow an entire directory but still want some HTML documents in that directory crawled and indexed. While by standard implementation the first matching robots.txt pattern always wins, Google's implementation differs in that it first evaluates all Allow patterns and only then all Disallow patterns. Yet, in order to be compatible to all robots, if you want to allow single files inside an otherwise disallowed directory, you need to place the Allow directive(s) first, followed by the Disallow, for example:

Allow: /folder1/myfile.html

Disallow: /folder1/

This example will Disallow anything in /folder1/ except /folder1/myfile.html, since the latter will match first. In case of Google, though, the order is not important.

[edit] Sitemap

Some crawlers support a Sitemap directive, allowing multiple sitemaps in the same robots.txt in the form:[5]

Sitemap: http://www.gstatic.com/s2/sitemaps/profiles-sitemap.xml

Sitemap: http://www.google.com/hostednews/sitemap_index.xml

[edit] Extended standard

An Extended Standard for Robot Exclusion has been proposed, which adds several new directives, such as Visit-time and Request-rate. For example:

User-agent: *

Disallow: /downloads/

Request-rate: 1/5         # maximum rate is one page every 5 seconds

Visit-time: 0600-0845     # only visit between 06:00 and 08:45 UTC (GMT)

The first version of the Robot Exclusion standard does not mention anything about the "*" character in the Disallow: statement. Some crawlers like Googlebot and Slurp recognize strings containing "*", while MSNbot and Teoma interpret it in different ways.

Why did this robot ignore my robots.txt in website?

It could be that it was written by an inexperienced software writer. Occasionally schools set their students "write a web robot" assignments. But, these days it's more likely that the robot is explicitly written to scan your site for information to abuse: it might be collecting email addresses to send email spam, look for forms to post links ("spamdexing"), or security holes to exploit.

Can I block just bad robots?

In theory yes, in practice, no. If the bad robot obeys /robots.txt, and you know the name it scans for in the User-Agent field. then you can create a section in your /robotst.txt to exclude it specifically. But almost all bad robots ignore /robots.txt, making that pointless. If the bad robot operates from a single IP address, you can block its access to your web server through server configuration or with a network firewall. If copies of the robot operate at lots of different IP addresses, such as hijacked PCs that are part of a large Botnet, then it becomes more difficult. The best option then is to use advanced firewall rules configuration that automatically block access to IP addresses that make many connections; but that can hit good robots as well your bad robots. Continue reading this entry »

Store proc in T-SQL SERVER 2005

Microsoft SQL Server provides the stored procedure mechanism to simplify the database development process by grouping Transact-SQL statements into manageable blocks.

Benefits of Stored Procedures

Why should you use stored procedures? Let’s take a look at the key benefits of this technology:

  • Precompiled execution. SQL Server compiles each stored procedure once and then reutilizes the execution plan. This results in tremendous performance boosts when stored procedures are called repeatedly.
  • Reduced client/server traffic. If network bandwidth is a concern in your environment, you’ll be happy to learn that stored procedures can reduce long SQL queries to a single line that is transmitted over the wire.
  • Efficient reuse of code and programming abstraction. Stored procedures can be used by multiple users and client programs. If you utilize them in a planned manner, you’ll find the development cycle takes less time.
  • Enhanced security controls. You can grant users permission to execute a stored procedure independently of underlying table permissions.

Stored procedures are very similar to user-defined functions, but there are subtle differences. For more information, read Comparing Stored Procedures and User-Defined Functions.

Structure

Stored procedures are extremely similar to the constructs seen in other programming languages. They accept data in the form of input parameters that are specified at execution time. These input parameters (if implemented) are utilized in the execution of a series of statements that produce some result. This result is returned to the calling environment through the use of a recordset, output parameters and a return code. That may sound like a mouthful, but you’ll find that stored procedures are actually quite simple.

Example

Let’s take a look at a practical example. Assume we have the table shown at the bottom of this page, named Inventory. This information is updated in real-time and warehouse managers are constantly checking the levels of products stored at their warehouse and available for shipment. In the past, each manager would run queries similar to the following:

SELECT Product, Quantity
FROM Inventory
WHERE Warehouse = ‘FL’

This resulted in very inefficient performance at the SQL Server. Each time a warehouse manager executed the query, the database server was forced to recompile the query and execute it from scratch. It also required the warehouse manager to have knowledge of SQL and appropriate permissions to access the table information.

We can simplify this process through the use of a stored procedure. Let’s create a procedure called sp_GetInventory that retrieves the inventory levels for a given warehouse. Here’s the SQL code:

CREATE PROCEDURE sp_GetInventory
@location varchar(10)
AS
SELECT Product, Quantity
FROM Inventory
WHERE Warehouse = @location

Our Florida warehouse manager can then access inventory levels by issuing the command

EXECUTE sp_GetInventory ‘FL’

The New York warehouse manager can use the same stored procedure to access that area’s inventory.

EXECUTE sp_GetInventory ‘NY’

Granted, this is a simple example, but the benefits of abstraction can be seen here. The warehouse manager does not need to understand SQL or the inner workings of the procedure. From a performance perspective, the stored procedure will work wonders. The SQL Sever creates an execution plan once and then reutilizes it by plugging in the appropriate parameters at execution time.

Now that you’ve learned the benefits of stored procedures, get out there and use them! Try a few examples and measure the performance enhancements achieved — you’ll be amazed!

Inventory Table

ID Product Warehouse Quantity
142 Green beans NY 100
214 Peas FL 200
825 Corn NY 140
512 Lima beans NY 180
491 Tomatoes FL 80
379 Watermelon FL 85

 

 

This article covers the basic of writing a stored procedure. It’s the first in a series on writing stored procedures.

<!–


–>

A stored procedure is written using Transact-SQL (T-SQL). T-SQL is a subset of ANSI SQL-92 that has extensions to the Standard. T-SQL includes variables, conditional logic, loops and flow control. We’ll use the pubs database for our examples. A stored procedure allows you to put code or business logic on the database server.

A stored procedure allows for more modular programming. You can create reusable, discrete pieces of functionality using stored procedures. Stored procedures have the parsing and execution plan built at the time they are created so they execute faster than dynamic SQL. If you have a stored procedure that manipulates large amounts of data, that data will remain on the server and not be transported across the network. You can also use stored procedures for security. You can grant users execute permissions on stored procedures without granting them permissions on objects manipulated by those stored procedures.

You can use SQL Server’s Enterprise Manager to create and edit stored procedures. A simple stored procedure looks like:

CREATE PROCEDURE spCaliforniaAuthors
AS
SELECT * FROM authors
WHERE state = 'CA'
ORDER BY zip

This stored procedure is called “spCaliforniaAuthors”. All it contains is a SELECT statement. All stored procedures that SQL Server provides start with “sp_” (and “xp_” for extended stored procedures) and I chose to almost follow this convention for this stored procedure. If you try to call a stored procedure that starts with “sp_” SQL Server will first search the MASTER database before searching the current database.

By default, only members of the dbo_owner role and db_ddladmin role can create stored procedures. Members of the dbo_owner role can give other users the ability to create procedures using a GRANT statement. That might look something like this:

GRANT CREATE PROCEDURE TO Development

You can check Books Online for more information on the GRANT statement.

You execute a stored procedure by typing it’s name or using the EXECUTE statement. To execute our stored procedure you can type

EXECUTE spCaliforniaAuthors

This will execute the stored procedure and return the results. If you are calling this procedure from an ASP page (or other client) you can use the EXECUTE statement as you SQL string to execute. In this case, our stored procedure will return a record set.


company announcements in UK


javascript Date functions


javascript string functions

Syntax

var myStr=new String(string);

String Object Properties

F: Firefox, IE: Internet Explorer

Property Description F IE
constructor Returns a reference to the function that created the object 1 4
length Returns the number of characters in a string 1 3
prototype Allows you to add properties and methods to an object 1 4

String HTML Wrapper Methods

The HTML wrapper methods return the string wrapped inside the appropriate HTML tag.

Method Description F IE
anchor() Creates an HTML anchor 1 3
big() Creates a string in a big font 1 3
blink() Creates a blinking string 1  
bold() Creates a string in bold 1 3
fixed() Creates a string as teletype text 1 3
fontcolor() Creates a string in a specified color 1 3
fontsize() Creates a string in a specified size 1 3
italics() Creates a string in italic 1 3
link() Creates a string as a hyperlink 1 3
small() Creates a string in a small font 1 3
strike() Creates a string with a strikethrough 1 3
sub() Creates a string as subscript 1 3
sup() Creates a string as superscript 1 3

String Object Methods

Method Description F IE
charAt() Returns the character at the specified position in a string 1 3
charCodeAt() Returns the Unicode of the character at the specified position in a string 1 4
concat() Joins two or more strings 1 4
fromCharCode() Converts Unicode values to characters 1 4
indexOf() Returns the position of the first found occurrence of a specified value in a string 1 3
lastIndexOf() Returns the position of the last found occurrence of a specified value in a string 1 3
match() Searches for a match between a regular expression and a string, and returns the matches 1 4
replace() Searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring 1 4
search() Searches for a match between a regular expression and a string, and returns the position of the match 1 4
slice() Extracts a part of a string and returns a new string 1 4
split() Splits a string into an array of substrings 1 4
substr() Extracts a specified number of characters in a string 1 4
substring() Extracts the characters in a string between two specified indices 1 3
toLowerCase() Converts a string to lowercase letters 1 3
toUpperCase() Converts a string to uppercase letters 1 3
toSource() Represents the source code of an object 1 -
valueOf() Returns the primitive value of a String object 1 4

JavaScript replace() Method

Definition and Usage

The replace() method finds a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring.

Syntax

stringObject.replace(regexp/substr,newstring)
Parameter Description
regexp/substr Required. A substring or a regular expression object. Read more about the RegExp object
newstring Required. The string to replace the found value in parameter 1

Example 1

Perform a case-sensitive search:

<script type=”text/javascript”>var str=”Say GoodMorning!”;
document.write(str.replace(“GoodMorning”, “HelloWorld”));

</script>

The output of the code above will be:

Say Hello World!