i am making an ionic app v2 in which i have to show 'today' instead of current date and 'yesterday' and 'tomorrow' also for respective dates. i tried using moment but it gives days till last week like last monday and reference time issue is also there with moment. i need for only these 3 days without reference time . can you tell me how to customize moment in ionic framework ? if you have any other suggestions than using moment . please tell. thanks in advance.
P.S: i want to implement this only in html code of ionic not in typescript code.
Just like this: moment().add(-1, 'days'). It will give you the previous day with the same exact current time that is on your local pc.
Ref here
Agreed that this will be difficult without JS/TS. In your .ts file couldn't you have 3 date member variables:
//Set up 3 new dates, defaulting them to today
yesterday: Date = new Date();
today: Date = new Date();
tomorrow: Date = new Date();
And then in your ctor or init method, set them up properly (below is likely not the most valid/efficient way, but is an example).
//Today is already set up from instantiation, but re-set tomorrow and yesterday
this.tomorrow.setDate(this.tomorrow.getDate() + 1);
this.yesterday.setDate(this.yesterday.getDate() - 1);
And then in your HTML, bind to them:
Yesterday was: {{yesterday?.toDateString()?.slice(0,10)}}
<br> Today is: {{today?.toDateString()?.slice(0,10)}}
<br> Tomorrow will be: {{tomorrow?.toDateString()?.slice(0,10)}}
Related
I have searched the site for similar questions but I did not find an answer specific to my situation. I am trying to display the current date in this formate: dd-MMM-yy, without the UTC time at the end. In the past in other functions I was able to have success using this: .setNumberFormat but in the function I am working on now, it won't work and it displays the full date.
This is my code I am using it in:
function updateLTD(e) {
// Code designed to insert current date to the "LTD" sheet.
var date = new Date();
if (e.range.columnStart != 1 || !e.value) return;
e.range.offset(0,3).setValue(date).setNumberFormat("dd-MMM-yy");
}
How to make this work in my current code? I appreciate any suggestions.
I'm creating a script in Apps Script that will count a habit streak. It will use today's date to find the correct column on the Sheet and count backwards from there until it hits a missed day. To get today's date, I'm trying to use:
Utilities.formatDate(new Date(), "EST", "yyyy.MM.dd");,
which keeps giving me the error:
"Cannot find method formatDate(object,string,string)"
My code uses exactly the same syntax as they show on the references page other than my changing the time zone from "GMT" to "EST", but changing it back to "GMT" or to "GMT-5" didn't fix it, so I'm kind of at a loss.
I think it's an issue creating the date object from "new Date()", as I've tried to use other date methods like Date.now() to which it throws up "TypeError: Cannot find function now in object [object Object]." I figured this may be something to do with my scopes but I checked and it looked like I had all the ones I needed.
I also tried creating the Date object separately and then passing the variable into formatDate but had the same result.
Code I've tried is:
var day = Utilities.formatDate(day, "GMT-5", "yyyy.MM.dd");
------
var day = Utilities.formatDate(new Date(), "EST", "yyyy.MM.dd");
------
var day = new Date();
var day = day.now();
Let me know if you need more to go off of than that. Any help is appreciated, even if it's just using a different method to set a variable equal to today's date, thanks!!!
I got same situation, but i can fix it.
You did Utilities.formatDate(new Date(), "EST", "yyyy.MM.dd");
You may change like the following
var date = new Date;
var today= new Date(date.getFullYear(), date.getMonth(), date.getDate());
today = Utilities.formatDate(today, "EST", "yyyy/MM/dd");
Try running the following test in your script:
function test() {
Logger.log(Utilities.formatDate(new Date(), "EST", "yyyy.MM.dd"));
// output: "2020.02.07"
}
I got the expected output. As #TheMaster points out, you probably have conflicting variable names somewhere.
As soon as I created a new project the utilities starting working properly.
From #TheMaster's comments:
Try isolating the issue> create a new project>add in only one function> one line with utilities. See minimal reproducible example
You probably have conflicting variables somewhere, like variables with the same name. day is a common name... you might've used it in any of the other file scripts attached.
I'm currently working with embarcadero c++, this is the first time I'm working with it so it's completely new to me.
What I'm trying to achieve is to get the current date, make sure the date has the "dd/MM/yyyy" format. When I'm sure this is the case I want to add a month to the current date.
So let's say the current date is 08/18/2016 this has to be changed to 18/08/2016 and then the end result should be 18/09/2016.
I've found that there is a method for this in embarcardero however I'm not sure how to use this.
currently I've only been able to get the current date like this.
TDateTime currentDate = Date();
I hope someone will be able to help me out here.
I figured it out.
After I've searched some more I found the way to use the IncMonth method on this page.
The example given my problem is as follows:
void __fastcall TForm1::edtMonthsExit(TObject *Sender)
{
TDateTime StartDate = edtStartDate->Text;
int Months = edtMonths->Text.ToInt();
TDateTime NextPeriod = IncMonth(StartDate, Months);
edtNextPeriod->Text = NextPeriod;
}
After looking at I changed my code accordingly to this
TDateTime CurrentDate = Date();
TDateTime EndDate = IncMonth(CurrentDate, 1);
A date object doesn't have a format like "dd/MM/yyyy". A date object is internally simply represented as a number (or possibly some other form of representation that really isn't your problem or responsibility).
So you don't have to check if it's in this format because no date objects will ever be in this format, they simply don't have a format.
You will have to do additions/subtractions on the Date object that the language or library gives you, THEN (optionally) you can format it to a human-readable string so it looks like 18/08/2016 or 18th of August 2016 or whatever other readable format that you choose.
It might be that the TRANSFER of a date between 2 systems is in a similar format, but then formatting the date like that is entirely up to you.
As for how to do that, the link you posted seems like a possible way (or alternatively http://docwiki.embarcadero.com/Libraries/Berlin/en/System.SysUtils.IncMonth), I'm afraid I can't give you an example as I'm not familiar with the tool/language involved, I'm just speaking generically about Date manipulations and they should ALWAYS be on the raw object.
I make a simple domain class
class Meetings {
Date when
String where
}
Then I run 'generate-all' on Meetings. I then start the app 'RunApp'.
In the app I'm able to to choose the month, day, and year for the when variable, however I can't choose the time as in hours:minutes (example 7:30). I wouldn't expect to be able to do this, but if I save the date it formats it as month, day, year, and then -00:00:00. How do I set the time using the date variable? or is there another way?
If you are using the datepicker tag in grails, it is pretty straight forward.
In the views folder under a domain class folder there is _form.gsp. Inside _form.gsp is a date picker tag.
<g:datePicker name="dateTimeVariableName" value="${dateTimeValue}"
default="${new Date().clearTime()}" precision="minute"/>
The keyword here is precision.
You should check the documentation. Its always a good idea. Hope this helps.
I can get the last day in php using cal_days_in_month(CAL_GREGORIAN, 03, 2014); function and then assign it to view. But I want to know is it possible to get the last day in current month using smarty date_format function?
Thanks in advance
I'm not sure you can solve this only using the date_format function. I wouldn't do it anyway, since this put way too much application logic into the template.
But... if you want to do this anyway, just add a template function to get what you want.
PHP:
$tpl = new Smarty();
$tpl->registerPlugin("function","lastdayofmonth", "smarty_function_lastdayofmonth");
$tpl->display('your_template.tpl');
function smarty_function_lastdayofmonth($params, Smarty_Internal_Template $template) {
return date("Y-m-t", strtotime($params['date']));
}
Smarty:
{assign var='datevar' value='2014-03-06'}
{lastdayofmonth date=$datevar}
Output:
2014-03-31
Keep in mind, this is just an easy example. There are more than one way to use plugins within Smarty.