Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including dehumanize-date with all npm packages installed. Try it out:

var dehumanizeDate = require("dehumanize-date")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

dehumanize-date v2.6.2

Parse dates in all the formats humans like to use.

dehumanize-date

Parse dates in all the formats humans like to use:

  • today/tomorrow/yesterday
  • next/this/last Wednesday
  • 12th January
  • 12th January 1950
  • 09-08-2008
  • 2008-08-09

Return dates in just the format that computers should use:

  • 2008-08-09

Build Status Dependency Status NPM version

testling badge

Installation

$ npm install dehumanize-date

Usage

A simple function which takes a string as an argument and returns a string in the form yyyy-mm-dd.

var date = dehumanizeDate(userInput);

The second parameter contains options. You can set whether to use US-style short dates, you can change what 'now' is for input like 'yesterday', and you can change the cutoff for 2-digit years that determines whether a given two-digit year is in the 21st or 20th century.

var date = dehumanizeDate(userInput, {usa: true, now: new Date(), cutoff: 80});

If you just want to use US formats for numerical dates you can also pass true as the second parameter:

var date = dehumanizeDate(userInput, true);

License

MIT

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free