Modifying date in ColdFusion - date

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>

Related

How to create a specific date in Google Script

I have a spreadsheet that asks people to enter in a day of the month when we need to send out a bill. What I want to do is create a calendar event based on that. So, essentially what I need is an event that starts at the current month, day from the spreadsheet, and continues to a specified point in time.
var monthlyDate = row[6]; // Seventh column, monthly date of payment
var curDate = new Date();
var curMonth = curDate.getMonth();
var curYear = curDate.getYear();
curDate.setDate(curMonth, monthlyDate, curYear);
Logger.log("Day of month: %s", monthlyDate);
Logger.log("Current Date: %s", curDate);
Logger.log("Current Date: %s", Date());
What I'm seeing is that the monthly date is coming in as a float "6.0" for example, and no matter what I enter in for monthlyDate in the setDate line, it keeps setting the date to 10/9/15 (Today is 10/15/15). I've hard-coded that value to many different numbers, but for some reason it's just not working.
How can I create a date (in any format) that follows the scheme "Current Month / Day from Speadsheet / Current Year" ?
The getMonth() method returns a "zero-indexed" number. So, it returns the number 9 for the 10th month. setDate() doesn't set the date, it sets the "Day of the Month". The name of that method is misleading.
Documentation - setDate()
So, the last two parameters that you are using in setDate() are doing nothing. You are setting the day of the month to 9.
If you want to set multiple date parameters at the same time, you need to use the new Date() method:
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
The month parameter accept values from 0 to 11, 0 is Jan and 11 is Dec
Date Reference

MS Access 2010 (Design View): return Monday of the current week with Monday as 1st day of the week

I need to make my Access query always return the Monday of the current week. I have seen a few solutions on Google/StackOverflow but they are written in SQL and I am a beginner in creating Access queries (I am using the Design view to make them).
Goal: The week should be considered as M T W T F S S. Then, the query should always return the Monday of the current week. Therefore, if it is Sunday, it should still return the Monday before, NOT the next week's Monday. Can anyone explain how to do this using the Design View in Access 2010?
Keep in mind that in this context we are working with dates, so if we do Date() - 1, we will get 1 day prior to today.
Date() ~ Today's date
DatePart(
"w" - Weekday
Date() - Today's date
2 - vBMonday (Access assumes Sunday is the first day of the week, which is why this is necessary.)
1 - vbFirstJan1 - This gets into using the first week of the year. We could have omitted this, as 1 is the default.
)
-1 - Subtract 1 from the DatePart value.
Values
Date() = 4/27/2015 (at time of this writing)
DatePart("w",Date(),2,1) = 1
DatePart("w",Date(),2,1)-1 = 0
So we have Date()-0... Okay, what's so great about that? Well, let's look at a more useful scenario where today's date is a day other than Monday.
Let's act like today is 4/28/2015 (Tuesday)
Date() = 4/28/2015
DatePart("w",Date(),2,1) = 2
DatePart("w",Date(),2,1)-1 = 1
So, from the outside, in; give me the current weekday value. (1 = Monday, 2 = Tuesday, etc.), and subtract 1 from that -> that's how many days we need to subtract from the current date to get back to the weekday value of 1 (Monday).
Here's a function that will do this:
Public Function DatePrevWeekday( _
ByVal datDate As Date, _
Optional ByVal bytWeekday As VbDayOfWeek = vbMonday) _
As Date
' Returns the date of the previous weekday, as spelled in vbXxxxday, prior to datDate.
' 2000-09-06. Cactus Data ApS.
' No special error handling.
On Error Resume Next
DatePrevWeekday = DateAdd("d", 1 - Weekday(datDate, bytWeekday), datDate)
End Function
As vbMonday is 2 and your date is today, you can use the core expression in a query:
PreviousMonday: DateAdd("d",1-Weekday(Date(),2),Date())

ColdFusion createdate()

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>

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.

Groovy get today's date at minute 00:00:00

I have this problem. I need to do the following:
get todays date
make a new date which will be today's date at 00:00:00
make another date which will be today's date at 23:59:59
For example. Today Date is 12-January-2012 19:00
How can i make a new date, which will be 12-January-2012 00:00 (the start of the current day)
It may seems easy, but i couldnt find any groovyway to get it, any help would be apreciated.
To get the date at midnight use Date.clearTime (docs):
dateAtMidnight = new Date()
dateAtMidnight.clearTime()
(Javadocs are for Groovy JDK < 2.0, clearTime() is declared void in Groovy JDK 2.0, preventing d = new Date().clearTime(). Comments indicate the original functionality may be restored, yay!)
For the comparison, instead of using <= 23:59:59, use < (the next day):
(aDate >= dateAtMidnight) && (aDate < (dateAtMidnight + 1))
An alternative way, but it sets the datetime (but it doesn't get the date merely)
dateAtMidnight = new Date()
dateAtMidnight.set(hourOfDay: 0, minute: 0, second: 0)