How can I get dates in this format?

V Munich

Пользователь
Регистрация
20.02.2014
Сообщения
85
Благодарностей
3
Баллы
8
Hello,

I already played a lot with the {-TimeNow.-} variable, but I can't find a way to get dates in this format:

20140322

2014-03-22

Note that I need the 0 above if the month number is lower than 10.

I can achieve this easily with php:

PHP:
<?php
echo date("Ymd");
<br>
echo date("Y-m-d");
?>
But how about Zenno? Is there a way to run PHP inside it? (Using ProjectMaker).
 

V Munich

Пользователь
Регистрация
20.02.2014
Сообщения
85
Благодарностей
3
Баллы
8
Hello,

I already played a lot with the {-TimeNow.-} variable, but I can't find a way to get dates in this format:

20140322

2014-03-22

Note that I need the 0 above if the month number is lower than 10.

I can achieve this easily with php:

PHP:
<?php
echo date("Ymd");
<br>
echo date("Y-m-d");
?>
But how about Zenno? Is there a way to run PHP inside it? (Using ProjectMaker).
I tried this in javascript to get 2014-03-22, but it returns nothing:

HTML:
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
    dd='0'+dd
}

if(mm<10) {
    mm='0'+mm
}

today = yyyy+'-'+mm+'-'+dd;
document.write(today);
Though, it works on JSFiddle: http://jsfiddle.net/Aaju5/
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
Код:
DateTime date1 = DateTime.Today;
var date = date1.ToString("d");
return date.Replace(".","");
C#
 
  • Спасибо
Реакции: V Munich

V Munich

Пользователь
Регистрация
20.02.2014
Сообщения
85
Благодарностей
3
Баллы
8
Код:
DateTime date1 = DateTime.Today;
var date = date1.ToString("d");
return date.Replace(".","");
C#
Thanks rostonix!

I did this modification to get the dates on the format I need:

Код:
DateTime date1 = DateTime.Today;
var date = date1.ToString("yyyy-MM-dd");
return date.Replace(".","");

// Returns 2014-03-22
Код:
DateTime date1 = DateTime.Today;
var date = date1.ToString("yyyyMMdd");
return date.Replace(".","");

// Returns 20140322
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
I missed order in your request)
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
Код:
var date = DateTime.Today.ToString("yyyyMMdd");
return date;
clean code)
 
  • Спасибо
Реакции: V Munich

V Munich

Пользователь
Регистрация
20.02.2014
Сообщения
85
Благодарностей
3
Баллы
8

wildjack

Client
Регистрация
19.07.2013
Сообщения
93
Благодарностей
8
Баллы
8
Very nice feature
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)