Nishanth J

Nishanth J

  • NA
  • 855
  • 13.6k

Replacing the String having Date and Time with = and ""

Mar 30 2020 8:29 AM
Whenever writing the date-and-time to an excel sheet the default cell format treats it as date and time and display in the format dd/mm/yyyy hh:mm, rather than displaying as dd-MMM-yyyy HH:mm:ss
 
But coming back to an Excel Sheet, whenever the date and time is enclosed with " "(double quotes) and prefixed with =(equals sign), it treats it as a string holding some values and displays exactly as it is rather than displaying default dd/mm/yyyy hh:mm format.
 
So as per the requirement, to achieve the string containing table data having dd/mm/yyyy hh:mm format need's to replace the date and time enclosed with double quotes with ="dd-MMM-yyyy HH:mm:ss"
 
Eg: 25-Feb-2020 15:27:58 need to be replaced with ="25-Feb-2020 15:27:58"
  1. <table>    
  2.    \n            
  3.    <thead>    
  4.       <tr>    
  5.          <th style=\"\">    
  6.             <div class=\"th-inner \">Login Name</div>    
  7.             <div class=\"fht-cell\"></div>    
  8.          </th>    
  9.          <th style=\"\">    
  10.             <div class=\"th-inner sortable\">Registered</div>    
  11.             <div class=\"fht-cell\"></div>    
  12.          </th>    
  13.          <th style=\"\">    
  14.             <div class=\"th-inner \">Registered Date <br>Time</div>    
  15.             <div class=\"fht-cell\"></div>    
  16.          </th>    
  17.          <th style=\"\">    
  18.             <div class=\"th-inner sortable\">User Response Count</div>    
  19.             <div class=\"fht-cell\"></div>    
  20.          </th>    
  21.          <th style=\"\">    
  22.             <div class=\"th-inner \">Test Start Date Time</div>    
  23.             <div class=\"fht-cell\"></div>    
  24.          </th>    
  25.          <th style=\"\">    
  26.             <div class=\"th-inner \">Test End Date Time</div>    
  27.             <div class=\"fht-cell\"></div>    
  28.          </th>    
  29.          <th style=\"\">    
  30.             <div class=\"th-inner \">Time Remaining</div>    
  31.             <div class=\"fht-cell\"></div>    
  32.          </th>    
  33.          <th style=\"\">    
  34.             <div class=\"th-inner \">User Status</div>    
  35.             <div class=\"fht-cell\"></div>    
  36.          </th>    
  37.       </tr>    
  38.    </thead>    
  39.    <tbody>    
  40.       <tr data-index=\"9\">    
  41.          <td style=\"\">njuser14</td>    
  42.          <td style=\"\">Yes</td>    
  43.          <td style=\"\">-</td>    
  44.          <td style=\"\">0</td>    
  45.          <td style=\"\">25-Feb-2020 15:27:58</td>    
  46.          <td style=\"\">25-Feb-2020 15:28:03</td>    
  47.          <td style=\"\">179</td>    
  48.          <td style=\"\">Paused</td>    
  49.       </tr>    
  50.       <tr data-index=\"10\">    
  51.          <td style=\"\">njuser15</td>    
  52.          <td style=\"\">Yes</td>    
  53.          <td style=\"\">-</td>    
  54.          <td style=\"\">0</td>    
  55.          <td style=\"\">25-Feb-2020 15:27:32</td>    
  56.          <td style=\"\">25-Feb-2020 15:27:42</td>    
  57.          <td style=\"\">179</td>    
  58.          <td style=\"\">Paused</td>    
  59.       </tr>    
  60.    </tbody>    
  61. </table>  
In the below coding snippets BatchDetails holding string containing table data, needs to be replaced and later assigned into session
  1. [System.Web.Services.WebMethod()]    
  2. public static string PersistBatchDetails(object BatchDetails)    
  3. {    
  4.     try    
  5.     {    
  6.         HttpContext.Current.Session["DashboardBatchInfo"] = BatchDetails;    
  7.     }    
  8.     catch (Exception ex){}    
  9.     return "S001";    
  10. }   

Answers (2)