Jieha Lee

Jieha Lee

  • 1.5k
  • 186
  • 8.6k

How to change date in dd/MMM/yyyy and time in hh:mm tt

Feb 1 2018 10:56 PM
How to change date from dd/mm/yyyy to dd/MMM/yyyy and hh:mm to hh:mm tt?
The <%=time.START_TIME%> is from the database which is store as 24H
I got error in code. the error is CS0103: The name 'date' does not exist in the current context
 
Here is the code:
  1. <%  
  2. if(obj.DATE.Substring(4, 2) == "01"){  
  3. var date = obj.DATE.Substring(6, 2) + " Jan " + obj.DATE.Substring(0, 4);  
  4. }  
  5. else if (obj.DATE.Substring(4, 2) == "02"){  
  6. var date = obj.DATE.Substring(6, 2) + " Feb " + obj.DATE.Substring(0, 4);  
  7. }  
  8. else if (obj.DATE.Substring(4, 2) == "03"){  
  9. var date = obj.DATE.Substring(6, 2) + " Mar " + obj.DATE.Substring(0, 4);  
  10. }  
  11. else if (obj.DATE.Substring(4, 2) == "04"){  
  12. var date = obj.DATE.Substring(6, 2) + " Apr " + obj.DATE.Substring(0, 4);  
  13. }  
  14. else if (obj.DATE.Substring(4, 2) == "05"){  
  15. var date = obj.DATE.Substring(6, 2) + " May " + obj.DATE.Substring(0, 4);  
  16. }  
  17. else if (obj.DATE.Substring(4, 2) == "06"){  
  18. var date = obj.DATE.Substring(6, 2) + " June " + obj.DATE.Substring(0, 4);  
  19. }  
  20. else if (obj.DATE.Substring(4, 2) == "07"){  
  21. var date = obj.DATE.Substring(6, 2) + " July " + obj.DATE.Substring(0, 4);  
  22. }  
  23. else if (obj.DATE.Substring(4, 2) == "08"){  
  24. var date = obj.DATE.Substring(6, 2) + " Aug " + obj.DATE.Substring(0, 4);  
  25. }  
  26. else if (obj.DATE.Substring(4, 2) == "09"){  
  27. var date = obj.DATE.Substring(6, 2) + " Sept " + obj.DATE.Substring(0, 4);  
  28. }  
  29. else if (obj.DATE.Substring(4, 2) == "10"){  
  30. var date = obj.DATE.Substring(6, 2) + " Oct " + obj.DATE.Substring(0, 4);  
  31. }  
  32. else if (obj.DATE.Substring(4, 2) == "11"){  
  33. var date = obj.DATE.Substring(6, 2) + " Nov " + obj.DATE.Substring(0, 4);  
  34. }  
  35. else{  
  36. var date = obj.DATE.Substring(6, 2) + " Dec " + obj.DATE.Substring(0, 4);  
  37. }  
  38. %>  
  39. <body>  
  40. <tr>  
  41. <td colspan="2" rowspan="2" bordercolor="#0066CC" style="border:2px solid #CCC; border-radius:20px; background:#CCC; font-family: tahoma;"><h2 align="center" style="font-family: sans-serif; font-size:calc(24px); padding:5px;">Your appointment is confirmed on:</h2>  
  42. <h1 align="center"><strong style="font-family: tahoma; font-size:27px;"><%=date %> </strong> at <strong style="font-family:tahoma; font-size:27px;"><%=time.START_TIME%></strong></h1></td>  
  43. </tr>  
  44. </body>  
Thanks

Answers (2)