ColdFusion createdate() - date

I am just learning about ColdFusion function CreateDate. But, when I use CreateDate the value output is different. I mean it changes month to day and day to month.
<cfoutput>
<cfset txtBirthDate='07-10-1983'>
<cfset valueOf_txtBirthDate = dateFormat(CreateDate(Year(txtBirthDate),Month(txtBirthDate),Day(txtBirthDate)),'YYYY-MMM-DD')>
#txtBirthDate#<br/><br/>
#valueOf_txtBirthDate#<br/>
</cfoutput>
The value of txtBirthDate is 07-10-1983, but the value of valueOf_txtBirthDate that CreateDate created is 1983-Jul-10. Why is it July? It is supposed to be October: 07(date), 10(month), 1983(year).
Is there something wrong with the format?

You are using createDate() in a very convoluted way. txtBirthDate isn't a date, so you shouldn't use it as an input for date functions like year(), month() etc. The input should already be a date object by the time you use a date function.
Let's say you start with the string 07-10-1983, where the format is mm-dd-yyyy.
txtBirthDate ='07-10-1983'; // dd-mm-yyyy
// extract the specific date parts from the string
yyyy = listLast(txtBirthDate, "-");
mm = listGetAt(txtBirthDate, 2, "-");
dd = listFirst(txtBirthDate, "-");
// create a date object out of those components
birthDate = createDate(yyyy, mm, dd);
// output the date object in human readable format
writeOutput(dateFormat(birthDate, "YYYY-MM-DD"));
(obviously in real code you'd not have those comments which serve only to state the obvious!)
Only ever use dateFormat() at the last point as you output it. For other date operations, use the actual date object: birthDate.

Because by default your date is mm/dd/yyyy format. So
<cfset txtBirthDate='07-10-1983'>
will be read as July 10th, 1983 by CF. Hence the outout...

You can use Java function to perform this.
This is how it works:
<cfset txtBirthDate='07-10-1983' />
<cfset formatter = createObject("java","java.text.SimpleDateFormat") />
<cfset formatter.init("dd-MM-yyyy") />
<cfset birthDate= formatter.parse(txtBirthDate) />

it seems like should do the trick:
<cfset txtBirthDate = '10-7-1983'>
#DateFormat(txtBirthDate, "MMM, D, YYYY")#
notice i reversed the position of month and day in cfset to make it come out right.

you can do something simple like that :
txtBirthDate = '07-10-1983'; //dd-mm-yyyy
arrayDate = listToArray(txtBirthDate, '-');
date_birthDate = createDate(arrayDate[3], arrayDate[2], arrayDate[1]);
writeOutput(lsDateFormat(date_birthDate, 'yyyy-mm-dd');

<cfscript>
txtBirthDate=CreateODBCDate("1983-10-07");
txtBirthDate=LSDateFormat(txtBirthDate, "dd/mm/yyyy");
</cfscript>
<cfoutput>
#txtBirthDate#
</cfoutput>

Related

talend format yyyy-MM-dd'T'HH:mm:ss.SSSz to yyyy-mm-dd HH:mm:ss

I am trying to change the date format in txmlmap component but its not working
i want change date format
from yyyy-MM-dd'T'HH:mm:ss.SSSz to yyyy-mm-dd HH:mm:ss
expected output:- yyyy-mm-dd HH:mm:ss
You can parse your string to a date using your source pattern and then format that date to a string using your target pattern:
TalendDate.formatDate("yyyy-mm-dd HH:mm:ss", TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss.SSSz", myDateString))
In almost all coding languages format is text, while date is a double. That means you must first make a date of the first expression, before setting the new format of that date. But in Your case the 'T' is some kind of special format that need to be replaced with a blanck space. I have no idea about what it would look like in talend but in VB it would look like this:
' from yyyy-MM-dd'T'HH:mm:ss.SSSz to yyyy-mm-dd HH:mm:ss
DateTxt = "2022-12-01'T'22:45:10"
DateTxt = Replace(DateTxt, "'T'", " ")
MyDate = CDate(DateTxt)
MsgBox Format(MyDate, "yyyy-mm-dd HH:mm:ss")

MomentJS date string adds one day

I don't understand why this date is saved as +1 day:
startdate = "2017-11-29T23:59:59.999Z";
var new_date = moment(startdate).format('DD/MM/YYYY'); // --> gives 30/11/2017
But if I do:
startdate = "2017-11-29";
var new_date = moment(startdate).format('DD/MM/YYYY'); // --> gives the correct date 29/11/2017
Any ideas?
Here is a jsfiddle showing this: http://jsfiddle.net/jbgUt/416/
Thanks!
If a time part is included, an offset from UTC can also be included as +-HH:mm, +-HHmm, +-HH or Z.
Add utc() to avoid it.
moment(startdate).utc().format('DD-MM-YYYY')
or
moment.utc(startdate).format('DD-MM-YYYY')
If you want to parse or display a moment in UTC, you can use moment.utc() instead of moment()
Late to the party on this one, but I did just convert a few of our product's date-time objects to https://moment.github.io/luxon/
Takes out the need for the .utc() method above.

set date default ion-datetime Ionic v-2

I have problem i try set the default date is today end disable day passed.
But when i set the default date is today i must convert date to string. So i can't calculator this.
Some body help me set the default date is today and calculator date. Thanks for reading my topic!
This is my code:
this.startDate = new Date().toISOString();
this.minDate = new Date().toISOString();
<ion-datetime
displayFormat="MMM DD, YYYY HH:mm"
[min]="minDate"
[(ngModel)]="startDate"
>
</ion-datetime>
From ionicv2 docs
https://ionicframework.com/docs/api/components/datetime/DateTime/
Ionic uses the ISO 8601 datetime format for its value. The value is
simply a string, rather than using JavaScript's Date object.
Additionally, when using the ISO datetime format, it makes it easier
to serialize and pass within JSON objects, and sending databases a
standardized format which it can be easily parsed if need be.
So, you can get the ISO string date by
startDate: String = new Date().toISOString();
and use it in the view like so
<ion-datetime
displayFormat="MMM DD, YYYY HH:mm"
[(ngModel)]="startDate"
>
If you want to disable backdated date, you can try this
min="2016-10-31"
and also you can specify the maxDate by
max="2020-12-12"
in your ion-datetime directive

Classic ASP - Display all dates within a certain date range

I was wondering if i could get some help.
I have a little script that gets a date range based on a persons input.
It outputs the date range like so
6/7/2014
6/27/2014
What i need to do is output each date between these 2 dates.
Any help would be greatly appreciated.
Cheers
Dates in Classic ASP are fairly easy to use. Try this first: http://www.classicasp.aspfaq.com/date-time-routines-manipulation/could-i-get-a-little-help-with-dates.html
Here's a demo of looping through a series of sequential dates:
dim dcount, newdate
dcount = 0
newdate = startdate
do
response.write(newdate & "<br />")
newdate = newdate + 1
loop until newdate > stopdate
Obviously you'd need to specify startdate and stopdate, though this could be done as a sub or function.

Modifying date in ColdFusion

How can I adjust a date in coldfusion to get the next day at 1AM?
the date is taken from a database, and stored as a string. I'm thinking the way to do it is through CreateDateTime and filling it with the time and date using year,month,day + 1 etc.
I'm just worried that it won't work when the next day falls on the next month
Using DateAdd() you can always be sure that it will take the context of the current date into account. So if it is August 31 and you add one day it will correctly make the date Sept 1st. It will also properly switch the year if you did the same on Dec 31st.
<cfset nextDate = dateAdd("d", 1, now()) />
<cfset nextDateWithTime = createDateTime(year(nextDate), month(nextDate), day(nextDate), 1, 0, 0) />
<cfoutput>#nextDateWithTime#</cfoutput>
Assuming the date is something which CF recognizes as a date, and contains date only, without time, you could do something like:
<cfscript>
function tomorrowOneAM(date) {
var resultValue = DateAdd("d",1,date);
resultValue = DateAdd("h",1,resultValue);
return resultValue;
}
</cfscript>