[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-19。"],[],[],null,["# Date shifting\n\nDates are a very common type of data. In cases where dates can be considered\nsensitive data or personally identifiable information (PII), you may need to\ngeneralize, obfuscate, or redact them.\n\nOne method for doing this is [generalization, or bucketing](/sensitive-data-protection/docs/concepts-bucketing).\nDepending on the use case and configuration, though, bucketing can remove the\nutility in the dates. For example, if you generalize all dates to just a year,\nthen you could lose the order in which events happen within that year. An\nalternate method for obfuscating dates that addresses this problem is\n*date shifting*.\n\nDate shifting techniques randomly shift a set of dates but preserve the sequence\nand duration of a period of time. Shifting dates is usually done in context to\nan individual or an entity. That is, each individual's dates are shifted by\nan amount of time that is unique to that individual.\n\nDate shifting example\n---------------------\n\nConsider the following data:\n\nIf you generalize these dates to year, then you get:\n\nBut now you've lost any sense of the sequence per user.\n\nInstead try date shifting:\n\nNote how the dates are different but the sequence and duration are preserved.\nThe magnitude that the dates were shifted was different between `user_id`s 1 and\n2.\n\nDate shifting in Sensitive Data Protection\n------------------------------------------\n\nA JSON object to configure this for Sensitive Data Protection's\n[`content.deidentify`](/sensitive-data-protection/docs/reference/rest/v2/projects.content/deidentify)\nmethod follows: \n\n deidentify_config {\n record_transformations {\n field_transformations {\n fields {\n name: \"date\"\n }\n primitive_transformation {\n date_shift_config {\n upper_bound_days: 100\n lower_bound_days: -100\n entity_field_id {\n name: \"user_id\"\n }\n crypto_key {\n unwrapped {\n key: \"123456789012345678901234567890ab\"\n }\n }\n }\n }\n }\n }\n }\n\nThe upper and lower bounds of the shift are specified by the `upper_bound_days`\nand `lower_bound_days` values, respectively. The context or scope that that\nshift will apply to is based on the `entity_id_field` value, which in this case\nis `\"user_id\"`.\n\nNote the use of a `crypto_key` as well. This is similar to how it's\nused in [pseudonymization](/sensitive-data-protection/docs/pseudonymization). The key will allow you\nto keep integrity of these date shifts across multiple requests or data runs.\n| **Warning:** For better security in production environments, use a [`KmsWrappedCryptoKey`](/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates#kmswrappedcryptokey) instead of an unwrapped key as illustrated in this example.\n\nResources\n---------\n\nFor more information about how to de-identify data using date shifting and\nother methods in Sensitive Data Protection, see:\n\n- [De-identifying sensitive data in text content](/sensitive-data-protection/docs/deidentify-sensitive-data#infotype_transformations)\n\nFor API reference information about primitive transformations in\nSensitive Data Protection, see:\n\n- [`DeidentifyConfig`](/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates#DeidentifyTemplate.DeidentifyConfig) object: The object in which you configure de-identification options.\n- [`PrimitiveTransformations`](/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates#primitivetransformation) object: Date shifting is a \"primitive transformation\" in Sensitive Data Protection.\n- [`DateShiftConfig`](/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates#dateshiftconfig) object: Object with which to configure the [`PrimitiveTransformations`](/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates#primitivetransformation) object. By specifying the `DateShiftConfig` object, you can shift dates by a random number of days."]]