how to get current date?

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

how to get current date?

#1

Postby t4nu » Tue Dec 22, 2015 8:20 am

Hi,
I want to get the current date and then assign it to a control.
I have assign the control to the script in its before control event.
It show up the date, but not the current date, instead it displayed the data of January 1st, 1970.

Here is the code of the script which I use:

Code: Select all

	

var tgl = new Date();
tables.ResignationForm.FormDate.value = tgl.getDate();

Can anybody help me fix the problem?
Thanks in advance for the help.[/code]
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

Re: how to get current date?

#2

Postby t4nu » Tue Dec 22, 2015 8:27 am

I change the assignment to this:

Code: Select all

	tables.ResignationForm.FormDate.value = tgl.getMonth()+1 + "/" + tgl.getDate() + "/" + tgl.getFullYear();
seems work. Is there any other way to get current date?
t4nu wrote:Hi,
I want to get the current date and then assign it to a control.
I have assign the control to the script in its before control event.
It show up the date, but not the current date, instead it displayed the data of January 1st, 1970.

Here is the code of the script which I use:

Code: Select all

	

var tgl = new Date();
tables.ResignationForm.FormDate.value = tgl.getDate();

Can anybody help me fix the problem?
Thanks in advance for the help.[/code]
[/code]
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#3

Postby Jon » Tue Dec 22, 2015 8:57 am

Code: Select all

tables.ResignationForm.FormDate.value = new Date();
Column FormDate needs to be of type DATE.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#4

Postby t4nu » Tue Dec 22, 2015 9:09 am

It is indeed date type.
Jon wrote:

Code: Select all

tables.ResignationForm.FormDate.value = new Date();
Column FormDate needs to be of type DATE.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#5

Postby Jon » Tue Dec 22, 2015 9:13 am

Then the code above should work.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#6

Postby t4nu » Tue Dec 22, 2015 9:16 am

which one? the first? The first work in the context it display the date, but not the current date, which I want to get.
The 2nd is work as expected, but I want to know if is there any other way more simple to get the current date.
Jon wrote:Then the code above should work.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#7

Postby Jon » Tue Dec 22, 2015 9:45 am

This code should work:

Code: Select all

tables.ResignationForm.FormDate.value = new Date();
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#8

Postby t4nu » Tue Dec 22, 2015 9:49 am

Thanks Jon, yes it's work :D
Sorry, I didn't notice of your previous reply.
Jon wrote:This code should work:

Code: Select all

tables.ResignationForm.FormDate.value = new Date();
0 x

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

#9

Postby Segi » Tue Dec 22, 2015 4:38 pm

I have a script called GLOBAL_FUNCTIONS with common functions that can be called from any script that I attach GLOBAL_FUNCTIONS to. These 2 functions retruns the date or time:

Code: Select all

// Returns current Date in the format mm/dd/yyyy
function getCurrentDate() {
     var d=new Date();

     var dateStr;

     dateStr=&#40;&#40;d.getMonth&#40;&#41;+1&#41; < 10 ? "0" + &#40;d.getMonth&#40;&#41; + 1&#41; &#58; &#40;d.getMonth&#40;&#41;+1&#41;&#41; + "/" + &#40;d.getDate&#40;&#41; < 10 ? "0" + d.getDate&#40;&#41; &#58; d.getDate&#40;&#41;&#41; + "/" + d.getFullYear&#40;&#41;

     return dateStr;
&#125;

// returns current time 
function getCurrentTime&#40;&#41; &#123;
     return new Date&#40;&#41;.toTimeString&#40;&#41;.toString&#40;&#41;.substring&#40;0,8&#41;;
&#125;
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

#10

Postby Steve James » Tue Dec 22, 2015 5:12 pm

DateServices is really handy and documented here

http://dev-docs.verj.io/ufs/doc/javadoc ... .String%29

eg

Code: Select all

var d=new Date&#40;&#41;; 
var dateStr = DateServices.formatDate&#40;d,'dd/MM/yyyy'&#41;;

var timeStr = DateServices.formatDate&#40;d,'HH&#58;mm&#58;ss'&#41;;
0 x


Who is online

Users browsing this forum: No registered users and 18 guests