Somebody could help me to how to change string date with format_date function.
Here is my code$datesql = format_date("2014-04-02 11:11:31", 'custom', 'Y-m-d');
drupal_set_message(t('date '.$datesql));
I suppose drupal to show this message "date 2014-04-02", but drupal just show the message "date", not $datesql. What is wrong in my code.
Thanks
Function "format_date" expects first parameter to be a timestamp, not a string. Try to wrap this first parameter with "strtotime" function and you will get a better result.
PS: do not include a variable in the first parameter of the "t" function. This could result in a lot of translatable strings. Pass it in the second parameter with "#myvar" as key. Check the "t" function documentation for more details.
try this
$date = new DateTime('2014-04-02 11:11:31');
$da = $date->format('Y-m-d H:i:s');
drupal_set_message('date '.$da,'status');
format_date() is use a covert a date in drupal created date not a convert a custom date
format_date($node->created, 'custom', 'Y-m-d');
Related
I want to get the actual time and add one day to it, setter below is datetime column type and it doesn't accept the date function. What should i do?
$password->setExpiretime(date("Y-m-d", time() + 86400));
You may use format method on an instance of DateTime class:
$tomorrow = new DateTime('tomorrow');
$password->setExpiretime($tomorrow->format('Y-m-d'));
Update
According to the comment submitted by the OP, if the return type should be DateTime Object, you may just use:
$tomorrow = new DateTime('tomorrow');
$password->setExpiretime($tomorrow);
I'm going loopy....
I want a date, in date format, for example
21/06/2017 17:23:04 GDT
I stamp this on a document, but I then want to display it on my xpage as:
21/06/2017 17:23
But I keep getting different results no matter what I do. I get the date from the onClick of a button using
var dt = new Date();
I then pass this into a function:
function AddObjectivesHistoryItem(doc, dt, action, username){
var ArrDocHistory:array = doc.getItemValueArray("History");
if(ArrDocHistory.length < 1){
// This should always return an object as it is created when an objectives document is first
// created but do this check to be safe and create an array if for some reason it doesnt exist
ArrDocHistory = [dt+"|"+action+"|"+username];
}else{
// append new value to the array
ArrDocHistory.push(dt+"|"+action+"|"+username);
}
doc.replaceItemValue("History",ArrDocHistory);
doc.replaceItemValue("LastUpdatedByName",username);
doc.replaceItemValue("LastUpdatedDate",dt);
}
I've tried using toLocaleString() and all others it seems but it wont work.
For example, toLocaleString() displays as 13-Mar-2018 15:02:15 on my xpage. It's close to what I want except it uses hyphens instead of slashes, and also displays the seconds.
I've tried using custom date pattern on my date field properties with no luck and I'm certain I'm missing something super obvious!?
Any pointers on how to firstly get the date like 21/06/2017 17:23:04 GDT and store as a date and secondly to then display it as 21/06/2017 17:23, this can be a string if it needs to be.
Thanks
You can get your date value as String in SSJS with:
var dateTimeFormat = new java.text.SimpleDateFormat("dd/MM/yyyy kk:mm");
var dateTimeString = dateTimeFormat.format(dt)));
If you want to store as text, java.text.SimpleDateFormat is best for converting a date server-side to a specific text format. It can also be used in a converter to manipulate to/from as well.
Given this code:
var ToDateDate = new String(Request.Form("Comm_ToDateTime"));
ToDateDate = ToDateDate.split("/");
var newToDateTime = ToDateDate[2]+"-"+ToDateDate[1]+"-"+ToDateDate[0]+" "+Request.Form("Comm_ToDateTime_TIME")+":00.000";
CurrentCommunication("Comm_ToDateTime") = newToDateTime;
CurrentCommunication.SaveChanges();
How can i save the date?
This way the date (as Days, month and year) got saved but the hours, minutos does not.
The final output for the newToDateTime variable is 2016-19-09 08:50:00.000
if i use this value (2016-19-09 08:50:00.000) in a barehand SQL update, it works
Turns out that i have to build the Date object with the values and then use getVarDate() mehtod to to pass from a Date Javascriopt object to a record’s date field value which at the end it is the same i was doing :S
Found my answer in this Sage CRM Community
I'm developing a custom validator of a date input in my workflow form and I get a null after parsing a date this is what I done:
// check dates can be parsed
str_expiryDate = field.form.prop_wfbxTestWorkFlow_NfDate.value;
console.log("Non conformite"+str_expiryDate);
str_reminderDate = field.form.prop_bpm_workflowDueDate.value;
console.log("echeance"+str_reminderDate);
Alfresco.logger.warn("Expiry Date: " + str_expiryDate + " | Reminder Date: " + str_reminderDate);
d_expiryDate = Date.parse(str_expiryDate);
console.log("nfDate"+str_expiryDate);
d_reminderDate = Date.parse(str_reminderDate);
console.log("Date echéance"+d_reminderDate);
and then i get this in console:
Non conformite2013-06-21T00:00:00.000+01:00 echeance2013-06-09T00:00:00.000+01:00
nfDatenull
Date echéancenull
How I can parse these two dates and then compare it? .thanks
Use Alfresco.util.fromISO8601(date)
According to the client-api docs
Convert an ISO8601 date string into a JavaScript native Date object
You are parsing the "value" of a date, not the date itself.
The best way to compare is, imho, using the format YYYYMMDD, and than compare it as a number.
Something like this (there is sure a far more elegant way to do that, but at this time it's the only one that got me):
var indexDate=str_expiryDate.indexOf("-");
var dayDate=str_expiryDate.substring(0, 2);
var monthDate=str_expiryDate.substring(3, 5);
var yearDate=fromData.substring(6, str_expiryDate.length+1);
int dataNew=yearDate+monthDate+dayDate;
and than compare the two dates value.
Obviously check if the index value are correct, I didn't double checked them.
Hope il helps.
Suppose the current month is "Oct". I want that it will add one month in current month i.e it will show "Nov". For this my code is written below but it gives exception that Input string was not in a correct format.
So please correct the code?
if (Convert.ToInt32(ddlMonth.SelectedIndex ) <= Convert.ToInt32(DateTime.Now.AddMonths(1).ToString()))
{
TotalBalanceUptoSelectedPreviousMonth();
}
This should probably work:
if (Convert.ToInt32(ddlMonth.SelectedIndex )
<= Convert.ToInt32(DateTime.Now.AddMonths(1).ToString("M")))
TotalBalanceUptoSelectedPreviousMonth();
However, it looks simpler like this:
if (Convert.ToInt32(ddlMonth.SelectedIndex) <= DateTime.Now.AddMonths(1).Month)
Total...();
Convert.ToInt32(DateTime.Now.AddMonths(1).ToString())
probably gives the exception since DateTime.Now.AddMonths(1).ToString() value is not castable to Int32.
I'll go out on a limb and say that this is what you're looking for:
if(ddlMonth.SelectedIndex <= DateTime.Now.AddMonths(1).Month)
{
TotalBalanceUptoSelectedPreviousMonth();
}
Instead of getting the date as a string and converting it, why not use the Month property of the DateTime struct (which is already an integer)?
(Oh...and SelectedIndex is already an integer as well, no need for the call to Convert)
You need to use DateTime.Now.AddMonths(1).Month.
Also you do not need to use the ToString method wrapped in a Convert.ToInt32 method as this is already an integer.