I've got a date variable that needs to be passed via connector to another application in a specific format. I've looked online at the @NOW() formula usage but I'm struggling with the syntax.
What I need is the date field to be written with the format as yyyyMMdd hh:mm
If I try "@NOW(yyyyMMdd hh:mm)" I get an error. And the format for "@NOW()" without modification isn't anywhere near the format I need.
Anyone have a good resource they could point me to for doing this?
Unfortunately Salesforce is very particular about what formats it accepts. The simplest solution is handle it on the Form side ( also simplest to debug ).
Here's the formula to create a Salesforce formatted now field (include this in your custom code block): <script> function sf_date(){ var now = new Date(); var dy = now.getDate(); var mo= now.getMonth()+1; var yr = now.getFullYear(); var ind = "AM"; var hr = now.getHours(); if(hr >= 12){ ind = "PM"; hr = hr - 12; } if(hr == 0){ hr = 12; } var min = now.getMinutes(); if(min < 10){ min = String.concat("0",min); } return mo+"/"+dy+"/"+yr+" "+hr+":"+min+" "+ind; } </script>
then in the field you wish to hold a SF formated now date, place the following formula in the formula field: sf_date()
Here's how I modified the script, it gives me an error now though...
<script> function sf_date(){ var now = new Date(); var dy = now.getDate(); if(dy < 10){ dy = String.concat("0",dy); } var mo= now.getMonth()+1; if(mo < 10){ mo = String.concat("0",mo); } var yr = now.getFullYear(); var ind = "AM"; var hr = now.getHours(); var min = now.getMinutes(); if(min < 10){ min = String.concat("0",min); } return yr+mo+dy+" "+hr+":"+min; } </script>
I think you're treating concat as a static function, when in reality it needs an instance to work from: String.concat vs String().concat http://www.w3schools.com/jsref/jsref_concat_string.asp
Try the below, and if that still doesn't work for you, try replacing your String.concat("0",n)s with String("0").concat(n) which should be guaranteed to work. ---
function sf_date(){ var now = new Date(); var dy = now.getDate(); if(dy < 10){ dy = String().concat("0",dy); } var mo= now.getMonth()+1; if(mo < 10){ mo = String().concat("0",mo); } var yr = now.getFullYear(); var ind = "AM"; var hr = now.getHours(); var min = now.getMinutes(); if(min < 10){ min = String().concat("0",min); } return yr+mo+dy+" "+hr+":"+min; }