Get the date and time of the last edit by default (/D is optional), the date created with /C flag, or get both with /B flag of files and folders.
Built with TypeScript - Includes full type definitions for use in TypeScript projects.
npm install -g getfiledateOr clone and install locally:
git clone https://github.com/jhauga/getFileDate.git
cd getFileDate
npm install
npm run build
npm linkgetFileDate [flags] [options] [files...]Flags control which date type to display:
/B- Output both date of last edit and date created/C- Output only the date created/D- Output the last edit date (default)
Note: Flags are case-insensitive (/b, /c, /d also work)
-d, --date [files...]- Get only the date-t, --time [files...]- Get only the time-h, --help- Show help message--version- Show version number
Some options support additional parameters:
--date:slash- Use slash (/) as date separator instead of dash (-)--date:dash- Use dash (-) as date separator (default)
Short options can be combined for convenience:
-dt # Get date and timeImportant: When combining options, only the last option can have a parameter.
-dt file.txt # Get date and time
-d:slash file.txt # Get date with slash separatorList all files and folders in current directory with last edit date and time:
getFileDateOutput:
03-03-2026 01:57 PM .
03-03-2026 01:37 PM ..
03-03-2026 01:57 PM .github
03-03-2026 01:57 PM getFileDate.code-workspace
03-03-2026 01:57 PM task.bat
Show created date only:
getFileDate /COutput:
03-03-2026 02:57 AM .
03-03-2026 02:37 AM ..
03-03-2026 02:57 AM .github
03-03-2026 02:57 AM getFileDate.code-workspace
Show both created and last edit dates:
getFileDate /BOutput:
[created] 03-03-2026 01:57 PM .
[last edit] 03-03-2026 02:57 AM .
[created] 03-03-2026 01:37 PM ..
[last edit] 03-03-2026 02:37 AM ..
[created] 03-03-2026 01:57 PM .github
[last edit] 03-03-2026 02:57 AM .github
Get only the date:
getFileDate --dateOutput:
03-03-2026 .
03-03-2026 ..
03-03-2026 .github
Get only the time:
getFileDate --timeOutput:
01:57 PM .
01:37 PM ..
01:57 PM .github
When specifying a single file, the filename is not shown in output:
getFileDate -d file.txtOutput:
03-03-2026
getFileDate -t file.txtOutput:
01:57 PM
Use slash separator instead of dash:
getFileDate --date:slash file.txtOutput:
03/03/2026
Specify multiple files separated by commas:
getFileDate -d fileA.txt,fileB.txt,fileC.txtOutput:
03-03-2026 fileA.txt
03-03-2026 fileB.txt
03-03-2026 fileC.txt
Combine flags and options:
getFileDate /C -t fileA.txt -d fileB.txt /D fileC.txtOutput:
01:57 AM fileA.txt
03-03-2026 fileB.txt
01:57 PM fileC.txt
You can also use getFileDate as a library in your Node.js or TypeScript projects:
const { getFileDates, formatDate, formatTime, formatBoth } = require('getfiledate');
async function example() {
// Get file dates
const dates = await getFileDates('./myfile.txt');
console.log('Created:', dates.created);
console.log('Modified:', dates.modified);
// Format dates
const formattedDate = formatDate(dates.modified, '-');
console.log('Date:', formattedDate); // e.g., "03-03-2026"
const formattedTime = formatTime(dates.modified);
console.log('Time:', formattedTime); // e.g., "01:57 PM"
const formattedBoth = formatBoth(dates.modified, '-');
console.log('Both:', formattedBoth); // e.g., "03-03-2026 01:57 PM"
}
example();import { getFileDates, formatDate, formatTime, formatBoth, FileDates } from 'getfiledate';
async function example(): Promise<void> {
// Get file dates - fully typed!
const dates: FileDates = await getFileDates('./myfile.txt');
console.log('Created:', dates.created);
console.log('Modified:', dates.modified);
// Format dates with type-safe parameters
const formattedDate: string = formatDate(dates.modified, '-');
console.log('Date:', formattedDate); // e.g., "03-03-2026"
const formattedTime: string = formatTime(dates.modified);
console.log('Time:', formattedTime); // e.g., "01:57 PM"
const formattedBoth: string = formatBoth(dates.modified, '/');
console.log('Both:', formattedBoth); // e.g., "03/03/2026 01:57 PM"
}
example();interface FileDates {
created: Date;
modified: Date;
}
function getFileDates(filePath: string): Promise<FileDates>;
function formatDate(date: Date, separator?: string): string;
function formatTime(date: Date): string;
function formatBoth(date: Date, separator?: string): string;
function padString(str: string, width: number): string;npm run build # Build the project
npm run watch # Build and watch for changes
npm run clean # Clean build artifactsnpm testgetFileDate/
├── src/
│ ├── bin/
│ │ └── getFileDate.ts # CLI executable (TypeScript)
│ └── lib/
│ ├── index.ts # Core date/time functions (TypeScript)
│ └── argParser.ts # Argument parsing logic (TypeScript)
├── test/
│ └── test.ts # Test suite (TypeScript)
├── dist/ # Compiled JavaScript output
├── tsconfig.json # TypeScript configuration
├── .gitignore
├── LICENSE
├── package.json
└── README.md
- Node.js >= 14.0.0
- TypeScript >= 5.0.0 (for development only)
MIT License - see LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.
