{"id":1248,"date":"2026-09-04T11:00:00","date_gmt":"2026-09-04T05:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/"},"modified":"2026-09-04T11:00:00","modified_gmt":"2026-09-04T05:30:00","slug":"apex-built-in-methods-string-date-math","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/","title":{"rendered":"Apex Built-in Methods: String, Date and Math with Examples"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apex Built-in Methods are ready-made tools that Salesforce gives you for everyday jobs. Need to cut a course code out of a name? Add 30 days to a start date? Round a fee to two decimals? You do not have to write that logic yourself, because Apex already has a method for it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, we cover the three groups you will use most: String, Date and Math. You already know <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/\">Apex data types<\/a> and how to call <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-methods-parameters-return-types\/\">Apex methods<\/a>. You also know the difference between <a href=\"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/\">static and instance members<\/a>, which matters here. Some built-in methods are static, such as <code>Date.today()<\/code>, while others run on a value, such as <code>name.toUpperCase()<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Apex Built-in Methods?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Built-in methods come with the Apex language. They belong to system classes like <code>String<\/code>, <code>Date<\/code>, <code>Datetime<\/code>, <code>Decimal<\/code> and <code>Math<\/code>. You can call them anywhere in your code without creating or deploying anything.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a kitchen that already has a peeler, a grater and a measuring cup. You could cut and measure everything with one knife, but the right tool is faster and gives a cleaner result. Apex Built-in Methods are those ready tools.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Apex Built-in Methods Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Hand-written code for common tasks is slow to write and easy to get wrong. However, Salesforce tests every built-in method, and each one works the same way in every org.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Less code.<\/strong> One call like <code>name.split(' ')<\/code> replaces a whole loop.<\/li>\n\n<li><strong>Fewer bugs.<\/strong> Date maths handles leap years and month lengths for you.<\/li>\n\n<li><strong>Clearer code.<\/strong> <code>startDate.addDays(30)<\/code> reads like plain English.<\/li>\n\n<li><strong>Correct money maths.<\/strong> <code>setScale<\/code> rounds fees in a predictable way.<\/li>\n\n<li><strong>Interview ready.<\/strong> Many coding questions test String and Date methods.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Apex Built-in Methods Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are two ways to call them. You call static methods on the class name, such as <code>String.isBlank(name)<\/code> or <code>Date.today()<\/code>. In contrast, you call instance methods on a value, such as <code>name.length()<\/code> or <code>startDate.addDays(7)<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-1-1024x640.png\" alt=\"Apex Built-in Methods diagram showing String, Date, Math and Decimal methods\" class=\"wp-image-1246\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-1-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-1-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Common built-in methods grouped by class.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Most methods return a new value instead of changing the original. For example, <code>name.toUpperCase()<\/code> gives you an uppercase copy, but <code>name<\/code> itself stays the same. So you must store the result in a variable if you want to keep it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">String Methods<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Strings hold text, and you will work with text in almost every class. The table below lists the String methods you will reach for most often.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Example<\/th><th>Result<\/th><\/tr><\/thead><tbody><tr><td>length()<\/td><td>&#8216;Apex Basics&#8217;.length()<\/td><td>11<\/td><\/tr><tr><td>toUpperCase()<\/td><td>&#8216;apex&#8217;.toUpperCase()<\/td><td>APEX<\/td><\/tr><tr><td>contains(text)<\/td><td>&#8216;Apex Basics&#8217;.contains(&#8216;Basics&#8217;)<\/td><td>true<\/td><\/tr><tr><td>startsWith(text)<\/td><td>&#8216;APX-101&#8217;.startsWith(&#8216;APX&#8217;)<\/td><td>true<\/td><\/tr><tr><td>substring(start, end)<\/td><td>&#8216;Apex Basics&#8217;.substring(0, 4)<\/td><td>Apex<\/td><\/tr><tr><td>split(separator)<\/td><td>&#8216;a,b,c&#8217;.split(&#8216;,&#8217;)<\/td><td>(a, b, c)<\/td><\/tr><tr><td>trim()<\/td><td>&#8216;  Apex  &#8216;.trim()<\/td><td>Apex<\/td><\/tr><tr><td>replace(old, new)<\/td><td>&#8216;Apex 101&#8217;.replace(&#8216;101&#8217;, &#8216;201&#8217;)<\/td><td>Apex 201<\/td><\/tr><tr><td>String.isBlank(text)<\/td><td>String.isBlank(&#8216;  &#8216;)<\/td><td>true<\/td><\/tr><tr><td>String.join(list, sep)<\/td><td>String.join(names, &#8216;, &#8216;)<\/td><td>Asha, Ravi<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Important String Details<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">String positions start at 0, just like List indexes. So <code>substring(0, 4)<\/code> takes the characters at positions 0, 1, 2 and 3. The end position itself is not included.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>String.isBlank<\/code> is safer than checking <code>name == ''<\/code>. It returns true for null, empty text and text that holds only spaces. So it covers all three &#8220;nothing here&#8221; cases at once.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For messages with many values, <code>String.format<\/code> is cleaner than many plus signs. You write placeholders like <code>{0}<\/code> and <code>{1}<\/code>, then pass the values in a list.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Date and Datetime Methods<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Dates appear in every business process, from course start dates to payment due dates. The table below shows the Date methods you will use most.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Example<\/th><th>Result<\/th><\/tr><\/thead><tbody><tr><td>Date.today()<\/td><td>Date.today()<\/td><td>Today&#8217;s date<\/td><\/tr><tr><td>Date.newInstance(y, m, d)<\/td><td>Date.newInstance(2026, 9, 15)<\/td><td>15 September 2026<\/td><\/tr><tr><td>addDays(n)<\/td><td>d.addDays(30)<\/td><td>30 days later<\/td><\/tr><tr><td>addMonths(n)<\/td><td>d.addMonths(2)<\/td><td>2 months later<\/td><\/tr><tr><td>daysBetween(other)<\/td><td>start.daysBetween(endDate)<\/td><td>Number of days<\/td><\/tr><tr><td>toStartOfMonth()<\/td><td>d.toStartOfMonth()<\/td><td>First day of that month<\/td><\/tr><tr><td>year(), month(), day()<\/td><td>d.month()<\/td><td>9<\/td><\/tr><tr><td>Datetime.now()<\/td><td>Datetime.now()<\/td><td>Current date and time<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Pass a negative number to go back in time. For example, <code>Date.today().addDays(-7)<\/code> gives the date one week ago. The <code>addMonths<\/code> method also handles short months correctly, so 31 January plus one month gives 28 or 29 February.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Datetime<\/code> values include a time and a time zone. The <code>format<\/code> method shows them in the running user&#8217;s time zone. For example, <code>Datetime.now().format('dd-MM-yyyy HH:mm')<\/code> gives something like <code>15-09-2026 14:30<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Math and Decimal Methods<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>Math<\/code> class covers common number tasks, while <code>Decimal<\/code> has its own methods for rounding money. The table below shows the most useful ones.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Example<\/th><th>Result<\/th><\/tr><\/thead><tbody><tr><td>Math.abs(n)<\/td><td>Math.abs(-250)<\/td><td>250<\/td><\/tr><tr><td>Math.max(a, b)<\/td><td>Math.max(4500, 6000)<\/td><td>6000<\/td><\/tr><tr><td>Math.min(a, b)<\/td><td>Math.min(4500, 6000)<\/td><td>4500<\/td><\/tr><tr><td>Math.mod(a, b)<\/td><td>Math.mod(47, 10)<\/td><td>7<\/td><\/tr><tr><td>Math.ceil(n)<\/td><td>Math.ceil(4.2)<\/td><td>5<\/td><\/tr><tr><td>Math.floor(n)<\/td><td>Math.floor(4.8)<\/td><td>4<\/td><\/tr><tr><td>setScale(2, mode)<\/td><td>fee.setScale(2, RoundingMode.HALF_UP)<\/td><td>1234.57 when fee is 1234.565<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Remember from the operators post that Apex has no <code>%<\/code> operator. So <code>Math.mod<\/code> is the only way to get a remainder. For money, always use <code>setScale<\/code> with a clear rounding mode, so every invoice rounds the same way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Apex Built-in Methods Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s build a small helper for Bright Path Tutors. It takes a course name, a fee and a start date. Then it creates a course code, an end date six weeks later and a monthly instalment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class CourseInfoHelper {\n\n    public static String courseCode(String name) {\n        if (String.isBlank(name)) {\n            return 'NA';\n        }\n        List&lt;String&gt; words = name.trim().split('\\\\s+');\n        String code = '';\n        for (String w : words) {\n            code += w.substring(0, 1).toUpperCase();\n        }\n        return code + '-' + Date.today().year();\n    }\n\n    public static Date endDate(Date startDate, Integer weeks) {\n        return startDate.addDays(weeks * 7);\n    }\n\n    public static Decimal monthlyInstalment(Decimal fee, Integer months) {\n        return (fee \/ months).setScale(2, RoundingMode.HALF_UP);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>courseCode<\/code> method first guards against empty names with <code>String.isBlank<\/code>. Then <code>trim<\/code> removes outer spaces, and <code>split('\\\\s+')<\/code> breaks the name into words, even when there are double spaces between them. The loop takes the first letter of each word with <code>substring(0, 1)<\/code> and makes it uppercase. Finally, it adds the current year.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next, <code>endDate<\/code> uses <code>addDays<\/code> to move the date forward by the number of weeks. Then <code>monthlyInstalment<\/code> divides the fee and rounds it to two decimals with <code>setScale<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is how to call it from anonymous Apex.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Date start = Date.newInstance(2026, 9, 15);\n\nSystem.debug(CourseInfoHelper.courseCode('salesforce apex basics'));\nSystem.debug(CourseInfoHelper.endDate(start, 6).format());\nSystem.debug(CourseInfoHelper.monthlyInstalment(10000, 3));\nSystem.debug(start.daysBetween(CourseInfoHelper.endDate(start, 6)) + ' days');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The log shows the code, the end date in your locale format, the instalment and the length in days.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>USER_DEBUG [3]|DEBUG|SAB-2026\nUSER_DEBUG [4]|DEBUG|27\/10\/2026\nUSER_DEBUG [5]|DEBUG|3333.33\nUSER_DEBUG [6]|DEBUG|42 days<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Your date format may differ, because <code>format()<\/code> follows the user&#8217;s locale setting. An Indian English locale shows 27\/10\/2026, while a US locale shows 10\/27\/2026.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Built-in Methods vs Writing Your Own<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Should you ever write your own version of a built-in method? The table below compares the two approaches.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Built-in method<\/th><th>Your own code<\/th><\/tr><\/thead><tbody><tr><td>Time to write<\/td><td>None<\/td><td>Minutes to hours<\/td><\/tr><tr><td>Tested by<\/td><td>Salesforce<\/td><td>You<\/td><\/tr><tr><td>Handles edge cases<\/td><td>Yes, such as leap years<\/td><td>Only if you remember them<\/td><\/tr><tr><td>Readability<\/td><td>High, well-known names<\/td><td>Depends on your naming<\/td><\/tr><tr><td>When it fits<\/td><td>Common tasks<\/td><td>Rules unique to your business<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is clear. Use Apex Built-in Methods for common tasks, and write your own only for rules that are unique to your business.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-2-1024x640.png\" alt=\"Apex Built-in Methods diagram comparing built-in methods with your own code\" class=\"wp-image-1247\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-2-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-2-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Built-in methods vs writing your own code.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Chaining Apex Built-in Methods<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Because most methods return a new value, you can call one method right after another. Developers call this chaining. For example, <code>name.trim().toUpperCase().replace(' ', '-')<\/code> turns <code>' apex basics '<\/code> into <code>'APEX-BASICS'<\/code> in one line.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apex runs the chain from left to right. First, <code>trim<\/code> removes the outer spaces. Next, <code>toUpperCase<\/code> changes the letters. Finally, <code>replace<\/code> swaps the space for a hyphen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Chaining keeps code short, but long chains get hard to read. So limit a chain to about three calls. If you need more, split the steps across a few clearly named variables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Built-in Methods and null Values<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Instance methods need a real value to run on. If the variable is null, Apex throws a NullPointerException before the method even starts. This is the most common crash with Apex Built-in Methods.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The safe navigation operator helps here. For example, <code>name?.toUpperCase()<\/code> returns null instead of crashing when <code>name<\/code> is null. For text, <code>String.isBlank(name)<\/code> is often the best first check, because it is a static method and accepts null safely.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Finding More Apex Built-in Methods<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This post covers the most common methods, but there are many more. The Apex Reference Guide lists every system class with its methods, parameters and return types. Bookmark it, because you will use it often.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In VS Code, you can also type a variable name followed by a dot. The Apex extension then shows a list of available methods for that type. This is a quick way to discover Apex Built-in Methods while you code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Apex Built-in Methods<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Calling a method on a null String. <code>name.length()<\/code> crashes when <code>name<\/code> is null, so check with <code>String.isBlank<\/code> first.<\/li>\n\n<li>Forgetting that strings are not changed in place. Store the result, such as <code>name = name.trim();<\/code>.<\/li>\n\n<li>Using <code>substring<\/code> with an end past the text length. It throws an error, so check <code>length()<\/code> first.<\/li>\n\n<li>Rounding money without a rounding mode. Use <code>setScale(2, RoundingMode.HALF_UP)<\/code> for clear results.<\/li>\n\n<li>Hardcoding date formats for users in many countries. Use <code>format()<\/code> to follow each user&#8217;s locale.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Apex Built-in Methods<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check the Apex Reference before writing a helper, because a built-in may already exist.<\/li>\n\n<li>Rely on <code>String.isBlank<\/code> for all empty-text checks.<\/li>\n\n<li>Pick <code>Decimal<\/code> and <code>setScale<\/code> for every currency calculation.<\/li>\n\n<li>Move dates with <code>addDays<\/code> and <code>addMonths<\/code> instead of adding numbers by hand.<\/li>\n\n<li>Wrap tricky combinations in your own small helper method with a clear name.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Write a method <code>daysUntilStart(Date startDate)<\/code> that returns how many days remain until a course starts. If the date has passed, return 0. Hint: use <code>Date.today().daysBetween(startDate)<\/code> and <code>Math.max<\/code> with 0.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexref.meta\/apexref\/apex_methods_system_string.htm\" target=\"_blank\" rel=\"noopener noreferrer\">String Class in the Apex Reference Guide<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexref.meta\/apexref\/apex_methods_system_date.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Date Class in the Apex Reference Guide<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexref.meta\/apexref\/apex_methods_system_math.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Math Class in the Apex Reference Guide<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Apex Built-in Methods are ready-made tools in classes like String, Date and Math.<\/li>\n\n<li>Static methods use the class name, while instance methods run on a value.<\/li>\n\n<li>String positions start at 0, and <code>substring<\/code> excludes the end position.<\/li>\n\n<li><code>addDays<\/code>, <code>addMonths<\/code> and <code>daysBetween<\/code> handle date maths safely.<\/li>\n\n<li>Use <code>setScale<\/code> with a rounding mode for money.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There is one more building block in Level 2. Next, learn how Apex handles records in <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/\">Apex sObjects: generic vs specific<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apex Built-in Methods are ready-made tools that Salesforce gives you for everyday jobs. Need to cut a course code out of a name? Add&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1245,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[8,96],"tags":[98,15,7,97],"swapz_series":[],"class_list":["post-1248","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","category-salesforce-developer","tag-apex","tag-beginner","tag-salesforce","tag-salesforce-developer"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apex Built-in Methods: String, Date and Math<\/title>\n<meta name=\"description\" content=\"Apex Built-in Methods for String, Date and Math explained with simple examples: split, substring, addDays, daysBetween, setScale and more.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex Built-in Methods: String, Date and Math\" \/>\n<meta property=\"og:description\" content=\"Apex Built-in Methods for String, Date and Math explained with simple examples: split, substring, addDays, daysBetween, setScale and more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-04T05:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\"},\"headline\":\"Apex Built-in Methods: String, Date and Math with Examples\",\"datePublished\":\"2026-09-04T05:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/\"},\"wordCount\":1527,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-built-in-methods-string-date-math-featured.png\",\"keywords\":[\"Apex\",\"Beginner\",\"Salesforce\",\"Salesforce Developer\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/\",\"name\":\"Apex Built-in Methods: String, Date and Math\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-built-in-methods-string-date-math-featured.png\",\"datePublished\":\"2026-09-04T05:30:00+00:00\",\"description\":\"Apex Built-in Methods for String, Date and Math explained with simple examples: split, substring, addDays, daysBetween, setScale and more.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-built-in-methods-string-date-math-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-built-in-methods-string-date-math-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex Built-in Methods featured image: title card with String and Date methods\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-built-in-methods-string-date-math\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex Built-in Methods: String, Date and Math with Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apex Built-in Methods: String, Date and Math","description":"Apex Built-in Methods for String, Date and Math explained with simple examples: split, substring, addDays, daysBetween, setScale and more.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/","og_locale":"en_US","og_type":"article","og_title":"Apex Built-in Methods: String, Date and Math","og_description":"Apex Built-in Methods for String, Date and Math explained with simple examples: split, substring, addDays, daysBetween, setScale and more.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-04T05:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a"},"headline":"Apex Built-in Methods: String, Date and Math with Examples","datePublished":"2026-09-04T05:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/"},"wordCount":1527,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-featured.png","keywords":["Apex","Beginner","Salesforce","Salesforce Developer"],"articleSection":["Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/","name":"Apex Built-in Methods: String, Date and Math","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-featured.png","datePublished":"2026-09-04T05:30:00+00:00","description":"Apex Built-in Methods for String, Date and Math explained with simple examples: split, substring, addDays, daysBetween, setScale and more.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-built-in-methods-string-date-math-featured.png","width":2400,"height":1260,"caption":"Apex Built-in Methods featured image: title card with String and Date methods"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apex Built-in Methods: String, Date and Math with Examples"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1248"}],"version-history":[{"count":0,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1248\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1245"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1248"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}