Skip to content

cotrVarDate

Creates a date variable

Aliases:

  • cotrVarDate
  • dateVariable
  • variableDate
  • date

cpp

#include <chrono>
auto myDate = std::chrono::system_clock::now();

csharp

DateTime myDate = new DateTime(year, month, day);

dart

DateTime myDate = DateTime(year, month, day);

go

// import "time"
var myDate = time.Date(year, time.Month, day, 0, 0, 0, 0, time.UTC)

haskell

-- Use the 'time' package to create a date variable:
import Data.Time
let myDate :: UTCTime = getCurrentTime

java

import java.time.LocalDate;
LocalDate myDate = LocalDate.of(year, month, day);

javascript

let myDate = new Date(year, month - 1, day);

javascriptreact

let myDate = new Date(year, month - 1, day);

kotlin

import java.time.LocalDate
val myDate: LocalDate = LocalDate.of(year, month, day)

perl

mymyDate = DateTime->new( year => year, month => month, day => day );

php

myDate = new DateTime('Y-m-d');

powershell

Terminal window
myDate = Get-Date -Year year -Month month -Day day

python

from datetime import datetime
my_date = datetime(year, month, day)

r

my_date <- as.Date('YYYY-MM-DD')

ruby

my_date = Date.new(year, month, day)

rust

// Rust does not have a built-in Date type.
// Use the chrono crate to create a date variable.
use chrono::{DateTime, Utc};
let my_date: DateTime<Utc> = Utc::now();

shellscript

Terminal window
# Bash doesn't have a dedicated date type, but you can store date strings:
myDate=\$(date)

swift

let myDate = Date()

typescript

let myDate: Date = new Date(year, month - 1, day);

typescriptreact

let myDate: Date = new Date(year, month - 1, day);