How can I get dates in this format?

  • Автор темы Автор темы V Munich
  • Дата начала Дата начала

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).
 
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/
 
Код:
Развернуть Свернуть Копировать
DateTime date1 = DateTime.Today;
var date = date1.ToString("d");
return date.Replace(".","");
C#
 
  • Спасибо
Реакции: V Munich
Код:
Развернуть Свернуть Копировать
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
 
I missed order in your request)
 
Код:
Развернуть Свернуть Копировать
var date = DateTime.Today.ToString("yyyyMMdd");
return date;

clean code)
 
  • Спасибо
Реакции: V Munich

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