This is how i call the constructor:
Date registerDate = new Date("2012","09","20","09","49","25","325");
And this is the output:
Sat Oct 20 09:49:25 GMT-0600 2012
"09" = October?
I get those parameters from a java web service in an xml, thats why they are strings, though, i get the same results with int values.
It's by design, I think:
Date() Constructor
public function Date(yearOrTimevalue:Object, month:Number, date:Number = 1, hour:Number = 0, minute:Number = 0, second:Number = 0, millisecond:Number = 0)
...
month:Number — An integer from 0 (January) to 11 (December).
...
In other words, it starts counting months from 0, so yes, October is 9. )
this is not a mistake, please look at the documentation. In a date, the value for the month is between 0 and 11, 0 for january and 11 for december. I hope this help you.
http://livedocs.adobe.com/flash/9.0_es/ActionScriptLangRefV3/Date.html
Related
I need to convert month number to month name.
I have date time as the date type - 2009-01-01 00:00:00.000
I also have 4-byte integer data type - 1
how do I convert this 1 to "January" for example?
i think you are in the data flow:
it is really easy to get MOnth Name in a script component from Date:
add a varchar column to your dataflow
Mark your date column for read access
enter the following script
Row.[NewColumnName] = Row.[Your Date Column].ToString("MMMM");
Result:
Here is a good translations for any date part to string formatting:
// create date time 2008-03-09 16:05:07.123
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
String.Format("{0:y yy yyy yyyy}", dt); // "8 08 008 2008" year
String.Format("{0:M MM MMM MMMM}", dt); // "3 03 Mar March" month
String.Format("{0:d dd ddd dddd}", dt); // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}", dt); // "4 04 16 16" hour 12/24
String.Format("{0:m mm}", dt); // "5 05" minute
String.Format("{0:s ss}", dt); // "7 07" second
String.Format("{0:f ff fff ffff}", dt); // "1 12 123 1230" sec.fraction
String.Format("{0:F FF FFF FFFF}", dt); // "1 12 123 123" without zeroes
String.Format("{0:t tt}", dt); // "P PM" A.M. or P.M.
String.Format("{0:z zz zzz}", dt); // "-6 -06 -06:00" time zone
Furthermore, you asked about quarters. I don't think it is as easy but here is something I stole from another answer.
Build DateTime extensions:
Normal Quarter:
public static int GetQuarter(this DateTime date)
{
return (date.Month + 2)/3;
}
Financial Year Quarter (This case is for quarters that start on April 1):
public static int GetFinancialQuarter(this DateTime date)
{
return (date.AddMonths(-3).Month + 2)/3;
}
Integer division will truncate decimals, giving you an integer result. Place methods into a static class and you will have an extension method to be used as follows:
Row.calendarQuarter = Row.[your Date Column].GetQuarter()
Row.fiscalQuarter = Row.[your Date Column].GetFinancialQuarter()
In SQL Server, one method is:
select datename(month, datefromparts(2000, 1, 1))
The first "1" is the column for the month. The year is arbitrary.
following steps:
create variable with datetime datatype and assigned value.
used MONTH function in ssis to extract month number and assigned to new variable with integer data type: #[User::newdata]= MONTH( #[User::dbdate])
finally used if else condition which manually compare all 12 months
(code available:1)
To save time I would like to iterate through a vector of month start and month end dates and make an API request each time and store the output from each request.
Say we start with a dataframe called dateTable holding the first and last day of the month for the date range:
firstDOM lastDOM
2016-05-01 2016-05-31
2016-06-01 2016-06-30
2016-07-01 2016-07-31
2016-08-01 2016-08-31
2016-09-01 2016-09-30
2016-10-01 2016-10-31
2016-11-01 2016-11-30
2016-12-01 2016-12-31
2017-01-01 2017-01-31
2017-02-01 2017-02-28
2017-03-01 2017-03-31
2017-04-01 2017-04-30
2017-05-01 2017-05-31
2017-06-01 2017-06-30
2017-07-01 2017-07-31
2017-08-01 2017-08-31
I would like to iterate through each row and paste the startDate and endDate into the following rest API request however I keep getting the following error when running this piece of code and I am not sure what's causing it:
for (i in 1:nrow(dateTable)) {
startDate <- dateTable$firstDOM
endDate <- dateTable$lastDOM
#Obtian the Volume of Mentions by Day using declared specs from above
qryMen <- GET(paste("https://newapi.brandwatch.com/projects/", projId, dataSpec
, "?queryId=", queryId, "&startDate=", startDate, "&endDate=", endDate
, '&pageSize=', pageSize, "&access_token=", accessToken$access_token, sep = ""))
}
#Error
Error: length(url) == 1 is not TRUE
Any help would be greatly appreciated!
Currently you are passing the entire vector in your for loop with each iteration and not indexing by the loop variable, i:
for (i in 1:nrow(dateTable)) {
startDate <- dateTable$firstDOM[[i]]
endDate <- dateTable$lastDOM[[i]]
...
}
Nonetheless, consider Map (or the equivalent mapply(..., SIMPLIFY=FALSE)) to iterate elementwise through the two columns. With this approach you can save a large list of objects (whatever your query returns) with number of elements equal to the rows of dataTable. You can then use this list for further operations.
api_fct <- function(startDate, endDate) {
qryMen <- GET(paste0("https://newapi.brandwatch.com/projects/", projId, dataSpec
, "?queryId=", queryId, "&startDate=", startDate, "&endDate=", endDate
, '&pageSize=', pageSize, "&access_token=", accessToken$access_token))
}
api_list <- Map(api_fct, dateTable$firstDOM, dateTable$lastDOM)
# api_list <- mapply(api_fct, dateTable$firstDOM, dateTable$lastDOM, SIMPLIFY=FALSE)
Couple things, your for loop isn't actually doing anything. You say for i in ... but you never reference i again. And, there's no reason to put the startDate and endDate in the loop. Also, it'd help if you post some sample data so that we can attempt to recreate what you are doing.
Anyway, The error is telling you what is wrong: you can't pass a vector of URLs to GET. Take everything you passed to GET() and just paste it into the console. You'll get back n URLs, n being the number of rows in your dateTable.
I'm assuming your R objects that you pass to GET (other than startDate and endDate) don't change? If that's the case, and you want to use a loop, you can preallocate a vector of the same length as the data you expect to return, then loop through your startDate and endDate, passing them into GET() and slotting them into your qryMen object.
startDate <- dateTable$firstDOM
endDate <- dateTable$lastDOM
qryMen <- vector(mode = "list", length = nrow(dataTable)
for (i in 1:nrow(dateTable)) {
qryMen[i] <- GET(paste("https://newapi.brandwatch.com/projects/", projId,
dataSpec, "?queryId=", queryId,
"&startDate=", startDate[i],
"&endDate=", endDate[i],
"&pageSize=", pageSize,
"&access_token=", accessToken$access_token, sep = ""))
}
Everyone,
I have a question that has stumped me for a day and can't figure out. What I am looking for is a formula in SSRS Expression that will tell me what the date is for the first day of the first ISO week of the current year.
For Example:
2014 would yield: 12/30/2013. The reason for this would be that the first ISO week of the 2014 year is from (12/30/2013) - (01/05/2014).
2013 would yield: 12/31/2012
I would appreciate any help anyone?
Thanks,
You can use this function:
Public Function dtFirstDayOfISOYear(ByVal intYear As Integer) as Datetime
'the first week of a ISO year is the week that contains the first Thursday of the year (and, hence, 4 January)
Dim intDayOfWeek As Integer = CInt(New DateTime(intYear, 1, 4).DayOfWeek)
'ISO weeks start with Monday
If intDayOfWeek < DayOfWeek.Monday Then intDayOfWeek = intDayOfWeek + 7
Return DateAdd(DateInterval.Day, -intDayOfWeek + 1, New DateTime(intYear, 1, 4))
End Function
And call it using an Expression like this:
=Code.dtFirstDayOfISOYear(2014)
You can also use a standalone Expression like this:
=DateAdd("d", (-1) * (CInt(New DateTime(2014, 1, 4).DayOfWeek) + IIf(CInt(New DateTime(2014, 1, 4).DayOfWeek) < DayOfWeek.Monday, 7, 0)) + 1, New DateTime(2014, 1, 4))
I have an sql statement which returns me the 1st day of the month:
DATEADD(month, DATEDIFF(month, 0, #input), 0)
How would I recreate this call using SQLFunctions.DateAdd and SQLFunctions.DateDiff?
Thanks in advance
If you are really using LINQ-to-SQL:
var zero = new DateTime(2000, 1, 1);
var resxxxx = (from p in ctx.Addresses
select new {
month = zero.AddMonths(SqlMethods.DateDiffMonth(zero, p.Date))
}
).FirstOrDefault();
The important part is month = zero.AddMonths(SqlMethods.DateDiffMonth(zero, p.Date)).
Note that I've used the zero = new DateTime(2000, 1, 1);, but any 1st of the month would be ok (1st jan 1980, 1st jul 1983, 1st dec 2100...). It's the two 0s in your SQL command. p.Date is the date of which you want to calculate the first of the month (so #input).
I got a website with an about section. there is some text about me including my current age. Lazy as I am I don't want to change that date after every birthday.
Is there an easy script to display my age based on my birthdate? I didn't find anything like that on the web.
Thx ahead.
You can do it in javascript. This should be more than enough to get you started..
// The date you were born
var birthDate = new Date(1990, 6, 19, 0, 0, 0, 0);
// The current date
var currentDate = new Date();
// The age in years
var age = currentDate.getFullYear() - birthDate.getFullYear();
// Compare the months
var month = currentDate.getMonth() - birthDate.getMonth();
// Compare the days
var day = currentDate.getDate() - birthDate.getDate();
// If the date has already happened this year
if ( month < 0 || month == 0 && day < 0 )
{
age--;
}
alert( age );