Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C#
* D lang.
* Java
* Nim
* Nim2
  + exercises
* XC=BASIC
* old
  ◇C++, ◇Clojure, ◇Scala


[ edit | logout ]
[ sandbox | passwd ]

Get the current date

See also std/times

import std/times

proc get_current_date(): string =
  now().format("yyyy'_'MM'_'dd")

proc main() =
  let date = get_current_date()
  echo date    # 2026_04_26

main()

Note that MM is the month, while mm is the minute. The format string "yyyy_MM_dd" wouldn't work since the underscore ('_') would also be treated as a format specifier. However, there's no such date/time specifier, so we'd get an error. To avoid the error, it must be put between apostrophes: '…'.

However, some characters don't have to be between apostrophes. In addition to spaces, the following characters can be inserted without quoting them: : - , . ( ) / [ ]. A literal ' can be specified with '' (double apostrophes).

Date object → string

See the example above.

String → date object

import std/times

let
  text = "20260503"
  dt: DateTime = parse(text, "yyyyMMdd")
  reformatted: string = dt.format("yyyy-MM-dd")

echo reformatted    # 2026-05-03
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 May 03, 12:15