c:\>echo %time%Ĭ:\> Get date and time c:\>echo %date%-%time%Īgreed. We can also get the current time from environment variables. It prints in 12 hour format when /t is added and in 24 hours format without /t c:\>time /tĪs you can see, the command prints the time in different formats. Similar to date command, we have the command time which lets us find the current system time. for /F 'tokens=2' %i in ('date /t') do echo %iĮxample: c:\>for /F 'tokens=2' %i in ('date /t') do echo %i You may want to exclude the day (like ‘Sun’ in the above example) and print only the date in MM/DD/YYYY format.
Sun How to get only the date in MM/DD/YYYY format?
In addition to date command, we also have an environment variable using which we can find today’s date. Just running date without any arguments prints the current date and then prompts to enter a new date if the user wants to reset it. To print today’s date on the command prompt, we can run date /t.