Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Need date imput to be month-day-year

Locked
JohnKlassen
Posts: 148
Joined: Wed Dec 05, 2012 4:56 am

Need date imput to be month-day-year

Unread post by JohnKlassen »

Hi,

I have a report that prompts for a date range and then selects the correct data from #dataTable#.

Here is the code to get the date range from the form:

Code: Select all

$fromdate = reformatField($formValue['vFrom'], 11, $quotes = false);
$todate   = reformatField($formValue['vTo'], 11, $quotes = false);
I have formatted 'vFrom' and 'vto' as '13-01-2007'. Everything works with this format.

Since I live in the USA, I would like the format to be '01-13-2007'. I have tried various ways to make this work but have been unsuccessful.

Any suggestions?

John
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

Re: Need date imput to be month-day-year

Unread post by admin »

John,

What do you get just by using $formValue['vFrom']?

Steven
JohnKlassen
Posts: 148
Joined: Wed Dec 05, 2012 4:56 am

Re: Need date imput to be month-day-year

Unread post by JohnKlassen »

Steven,

I realize now that I have 2 different issues. The first is how to display the date in month-day-year to my user. The second is how to format the same date to year-month-day in my WHERE clause.

I resolved the month-day-year display on the form by setting the format in the text tab for vFrom to '01-13-2007' and using the following"

Code: Select all

$fromdate = $formValue['vFrom'];
as you suggested.

I have not figured out how to format the date as year-month-day so I can use it with BETWEEN date ranges. I tried "

Code: Select all

$yearfromdate = date("Y-m-d", $fromdate);
but the result for '01-16-2013' came out as '1970-01-01'.

Thanks for fixing the first problem. Any suggestions for the second one?

BTW, is there any documentation for some of these commands like 'reformat' so that I know what the pareameters are doing?

Thanks,

John
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

Re: Need date imput to be month-day-year

Unread post by admin »

John,

Here's the wiki link..

http://wiki.nubuilder.com/tiki-index.ph ... rmatField_

I suggest you refer to your fields with hash variables..

Code: Select all


print $formValue['vFrom'];

print '#vFrom#';  //-- use this instead

should give you - 13-01-2007

Code: Select all


$fromdate = reformatField('#vFrom#', 7);
$todate   = reformatField('#vTo#', 7);

$s = "SELECT * FROM invoice WHERE inv_date BETWEEN $fromdate AND $todate"
print $s;

should give you - SELECT * FROM invoice WHERE inv_date BETWEEN '2007-01-13' AND '2007-01-26'

Steven
JohnKlassen
Posts: 148
Joined: Wed Dec 05, 2012 4:56 am

Re: Need date imput to be month-day-year

Unread post by JohnKlassen »

Steven,

First of all, thanks for the link to the wiki page. I had looked at it a couple of months ago and had not thought about looking there.

Secondly, thanks for pointing me in the right direction. Since I have the default format for vfrom as '01-13-2007', I had to use reformat with option 9 or 13 to get 'Y-m-d'.

The good news is that it works.

Thanks,

John
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

Re: Need date imput to be month-day-year

Unread post by admin »

Excellent!
Locked